Laravel Seeding

Laravel Seeding

Writing Seeders

Php artisan make:seeder UsersTableSeeder
<?php

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

class DatabaseSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        DB::table('users')->insert([
            'name' => str_random(10),
            'email' => str_random(10).'@gmail.com',
            'password' => bcrypt('secret'),
        ]);
    }
}

Running Seeders

Composer dump-autoload
Php artisan db:seed

php artisan db:seed --class=UsersTableSeeder
Php artisan migrate:refresh --seed

Laravel Seeding — Structure map

Clickable & Draggable!

Laravel Seeding — Related pages: