factory method on relations #40814
-
$customer = Customer::factory()->create();
$customer->addresses()->factory()->create(['city' => 'Miami']);
$customer->addresses()->factory()->create(['city' => 'New York']); We know the Address model, its factory, and the value of the Would be cool if Laravel added a factory method on relationship classes to set this up |
Beta Was this translation helpful? Give feedback.
Answered by
chuckrincon
Feb 4, 2022
Replies: 1 comment 1 reply
-
Hi there ✋🏻
Actually we have this feature, you could try using the Factory Relationships and the Sequences to get the same result: Customer::factory()
->has(
Address::factory(2)
->state(new Sequence(
['city' => 'Miami'],
['city' => 'New York'],
))
)
->create(); |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
dillingham
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi there ✋🏻
Actually we have this feature, you could try using the Factory Relationships and the Sequences to get the same result: