I have the following factory:
class JobFactory extends Factory
{
public function definition(): array
{
return [
"title" => fake()->sentence(),
"company_id" => Company::factory(),
"contact_id" => Contact::factory(),
];
}
}
Each Contact belongs to a Company, so ideally I'd like the jobs.company_id field to match the contacts.company_id.
Is there an easy way to do this?
You can use the factory methods for relationships.
https://laravel.com/docs/11.x/eloquent-factories#belongs-to-relationships