我刚刚更新了我的Laravel安装从7到8,我正试图将我的旧工厂转换为新的基于类的工厂。
我有以下Laravel 7工厂;
$bottles = factory(Bottle::class, rand(1, 5))->create([
'email' => $faker->safeEmail
])
我如何将其转换为Laravel 8。rand部分似乎不起作用,我试过了;
$bottles = Bottle::factory()->rand(1, 5)->create([
'email' => $this->faker->safeEmail
]);
但我得到以下错误;
Call to undefined method DatabaseFactoriesBottleFactory::rand()
您可以为laravel8工厂使用count()方法:
$bottles = Bottle::factory()->count(rand(1, 5))->create([
'email' => $this->faker->safeEmail
]);