Laravel Seeder Example

https://laravel.com/docs/5.8/seeding

php artisan make:seeder LanguagesTableSeeder

Seed Language Table

<?php

use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;

use Carbon\Carbon;

class LanguagesTableSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        $languages = [];
        $languages[] = [
            'name' => 'English', 
            'code' => 'en', 
            'enabled' => 1, 
            'sort_order' => 0, 
            'created_at' => Carbon::now()->toDateTimeString()
        ];

        $languages[] = [
            'name' => '繁體中文', 
            'code' => 'zhtw', 
            'enabled' => 1, 
            'sort_order' => 1, 
            'created_at' => Carbon::now()->toDateTimeString()
        ];

        DB::table('languages')->insert($languages);
    }
}

DatabaseSeeder

<?php

use Illuminate\Database\Seeder;

class DatabaseSeeder extends Seeder
{
    /**
     * Seed the application's database.
     *
     * @return void
     */
    public function run()
    {
        $this->call(LanguagesTableSeeder::class);
    }
}

 

Command

php artisan db:seed

php artisan db:seed --class=UsersTableSeeder

php artisan migrate --seed