首页 > 代码库 > 填充数据

填充数据

1.定义工厂函数
$factory->define(App\Test(model类名)::class, function (Faker\Generator $faker) {
return [
‘name‘ => $faker->name,
‘email‘ => $faker->email,
‘password‘ => str_random(10),
‘remember_token‘ => str_random(10),
‘admin‘ => true,
];
});
2.DatabaseSeeder.php中定义run
public function run()
    {
factory(‘App\TestModel‘, 50)->create();
}

3. php artisan db:seed

填充数据