Tutorial by Examples

To control your database in Laravel is by using migrations. Create migration with artisan: php artisan make:migration create_first_table --create=first_table This will generate the class CreateFirstTable. Inside the up method you can create your columns: <?php use Illuminate\Database\Sche...
Migrations in a Laravel 5 application live in the database/migrations directory. Their filenames conform to a particular format: <year>_<month>_<day>_<hour><minute><second>_<name>.php One migration file should represent a schema update to solve a particu...
Creating a new migration file with the correct filename every time you need to change your schema would be a chore. Thankfully, Laravel's artisan command can generate the migration for you: php artisan make:migration add_last_logged_in_to_users_table You can also use the --table and --create fla...
Each migration should have an up() method and a down() method. The purpose of the up() method is to perform the required operations to put the database schema in its new state, and the purpose of the down() method is to reverse any operations performed by the up() method. Ensuring that the down() me...
Once your migration is written, running it will apply the operations to your database. php artisan migrate If all went well, you'll see an output similar to the below: Migrated: 2016_07_21_134310_add_last_logged_in_to_users_table Laravel is clever enough to know when you're running migration...
What if you want to rollback the latest migration i.e recent operation, you can use the awesome rollback command. But remember that this command rolls back only the last migration, which may include multiple migration files php artisan migrate:rollback If you are interested in rolling back all o...

Page 1 of 1