php artisan make:factory StatusFactory
自动生成的代码文件
database/factories/StatusFactory.php
public function definition()
{
$date_time = $this->faker->date . ' ' . $this->faker->time;
return [
'user_id' => $this->faker->randomElement(['1','2','3']),
'content' => $this->faker->text(),
'created_at' => $date_time,
'updated_at' => $date_time,
];
}
php artisan make:seeder StatusesTableSeeder
自动生成的代码文件StatusesTableSeeder
class StatusesTableSeeder extends Seeder
{
public function run()
{
Status::factory()->count(100)->create();
}
}
class DatabaseSeeder extends Seeder
{
public function run()
{
Model::unguard();
$this->call(UsersTableSeeder::class);************
$this->call(StatusesTableSeeder::class);
Model::reguard();
}
}
php artisan migrate:refresh --seed