Model factories with relationships by using magic methods

When using factories with relationships, Laravel also provides magic methods:

User::factory()->hasPosts()->create();

Perhaps not the most IDE friendly option, but I think it feels more readable.

1// magic factory relationship methods
2User::factory()->hasPosts(3)->create();
3 
4// insted of
5User::factory()->has(Post::factory()->count(3))->create();