Model factories with relationships by using magic methods

Fecha

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.

// magic factory relationship methods
User::factory()->hasPosts(3)->create();

// insted of
User::factory()->has(Post::factory()->count(3))->create();