生成Seeder文件
php artisan make:seeder UserSeeder
运行后会在database/seeds目录下生成UserSeeder.php 文件
编辑UserSeeder.php 文件
public function run()
{
//生成30条用户数据,并指定第一条账号的账号邮箱
$users = factory(\App\User::class,30)->create();
$user = $users[0];
$user->name = 'NODJOY';
$user->email = 'nodjoy@163.com';
$user->save();
}
编辑工厂文件database/factories/UserFactory.php
$factory->define(App\User::class, function (Faker $faker) {
return [
'name' => $faker->name,
'email' => $faker->unique()->safeEmail,
'password' => bcrypt('admin888'),
'remember_token' => str_random(10),
];
});
编辑执行Seeder文件database/seeds/DatabaseSeeder.php
public function run()
{
// $this->call(UsersTableSeeder::class);
$this->call(UserSeeder::class);
}
执行填充数据命令
php artisan db:seed
喜欢这篇文章的话 打赏一下吧!