recycle() method in factories
Hello,
I have this code in a seeder.
public function run(): void
{
$companies = Company::all();
Theme::withoutEvents(function () use ($companies) {
Theme::factory()->recycle($companies)->count(50)->create();
});
}
I get an error message saying that the company_id hasn't a default value.
What am I doing wrong with the recycle() method ?
https://laravel.com/docs/10.x/eloquent-factories#recycling-an-existing-model-for-relationships
Thanks for your help.
V
how does your Theme factory definition look like? do you have company_id defined like this?
return [
//...
'company_id' => Company::factory(),
];
and make sure you have at least one Company available at the time when you run $companies = Company::all();
@s4muel Oh I haven't defined this field, I thought it was automatically defined via the recycle() method.
Please or to participate in this conversation.