我刚刚将Laravel的安装版本从7更新到了8,并且我正在尝试将旧工厂转换为新的基于类的工厂。
我有以下Laravel 7工厂;
$bottles = factory(Bottle::class, rand(1, 5))->create([
'email' => $faker->safeEmail
])
我如何将其转换为Laravel 8。
$bottles = Bottle::factory()->rand(1, 5)->create([
'email' => $this->faker->safeEmail
]);
但是我得到了以下错误;
Call to undefined method Database\Factories\BottleFactory::rand()
您可以对laravel8工厂使用count()方法:
$bottles = Bottle::factory()->count(rand(1, 5))->create([
'email' => $this->faker->safeEmail
]);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句