laravel 数据填充

进入database下面的factory

$factory->define(User::class, function (Faker $faker) {
return [
'name' => $faker->name,
'email' => $faker->unique()->safeEmail,
'email_verified_at' => now(),
'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password
'remember_token' => Str::random(10),
];
});


$factory->define(\App\Models\Post::class, function (Faker $faker) {
return [
'title' => $faker->sentence(6),
'content' => $faker->paragraph(10),
];
});

然后进入目录使用tinker
php artisan tinker
执行

    factory(App\Models\Post::class,50)->make()

 //展示不创建 要创建到数据库使用create
上一篇:File


下一篇:JAVA IO流