Laravel (5.7) Migration & Seed

In the main directory of our project we can use  make:migration  command for create a migration file. Here is example about creating language table:

php artisan make:migration create_language_table --create=language

Then we can see project\database\migrations\2018_12_30_084205_create_language_table.php   file. Its created with migration command.

Open the 2018_12_30_084205_create_language_table.php file and see the up function.

public function up()
{
    Schema::create('language', function (Blueprint $table) {
        $table->increments('id');
        $table->timestamps();
    });
}

We want to add name, iso_code, active columns to language table

 public function up()
    {
        Schema::create('language', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name',32);
            $table->string('iso_code',2);
            $table->boolean('active');
            $table->timestamps();
        });
    }

Use the migrate command for create table:

php artisan migrate

Lets make database seed

Use this command and create seeder class:
php artisan make:seeder LanguageTableSeeder
Now we have seeder class project\database\seeds\LanguageTableSeeder.php lets open and insert values.

DB::table('language')->insert([
    [
        'name' => 'english',
        'iso_code' => 'en',
        'active' => true,
    ],
    [
        'name' => 'deutsch',
        'iso_code' => 'de',
        'active' => true,
    ]
]);

for insert data

composer dump-autoload

php artisan db:seed --class=LanguageTableSeeder

If you want to make multiple class seed, open project\database\seeds\DatabaseSeeder.php  write run classes

public function run()
{
    $this->call([
        LanguageTableSeeder::class,
        ExampleTableSeeder::class,
        AnotherTableSeeder::class,
    ]);
}

use this command for seed all data:

php artisan db:seed