Migrations and database seed
Now, let's exercise some commands that we briefly saw in the first chapter and create our migrations and seeds in a different way.
- Open your Terminal window on the
chapter-04
folder and type the following command:
docker-compose exec php-fpm bash
- Inside the container root bash, type the following command:
php artisan make:model Bike -m
Note that we are using the -m
flag to create the migration file together with the creation of Bike Model. So now, we have two new files in our application:
project/app/Bike.php
project/database/migrations/XXXX_XX_XX_XXXXXX_create_bikes_table.php
Creating the migration boilerplate
As we saw previously, the new files only have the boilerplate code that's been created by the Laravel engine. Let's add some content to the Bike model and migration file.
- Open
project/app/Bike.php
and add the following code inside the Bike model function:
protected $fillable = [ 'make', 'model', 'year', 'mods', 'picture' ];
- Now, we need to add...