読者です 読者をやめる 読者になる 読者になる

Laravel Database Seed

  • create a Seed file  

php artisan make:seeder UsersSeeder

  • register Seed file

@DatabaseSeeder.php

use Illuminate\Database\Seeder;

class DatabaseSeeder extends Seeder
{
public function run()
{
$this->call(UsersSeeder::class);
}
}

  • define UsersSeeder.php

use Illuminate\Database\Seeder;
use App\User;

class UsersSeeder extends Seeder
{

public function run()
{
$user = new User();
$user->name = "test";
$user->email = "test@test.com";
$user->password = bcrypt("testtest");
$user->save();
}
}

  • execute

php artisan db:seed