I’m working with Laravel and need to create 6 job instances using a factory. Out of these 6 jobs, I want 3 to have a type of ‘software’ and 3 to have a type of ‘QA’.
Here’s my current approach using the Job seeder:
$tags = Tag::factory(3)->create();
Job::factory(6)->create()->each(function ($job) use ($tags) {
$tag = $tags->random(3);
$job->tags()->attach($tag);
});
New contributor
Ahamed Rasni Nathees is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.