thephpleague / factory-muffin

Enables the rapid creation of objects for testing
https://factory-muffin.thephpleague.com/
MIT License
532 stars 72 forks source link

Is there any way to create a model related to another model(s) via pivot table? #440

Open djagya opened 7 years ago

djagya commented 7 years ago

Hi, Is there any way to automatically create a row inside the pivot table for a model? For example: Post <-> Author

If I want to create a Post related to an Author, how do I specify a definition for that? Unfortunately that doesn't work:

$fm->define(Post::class)->setDefinitions([
    'title' => Faker::name(),
    'author' => 'factory|Author',
]);

Should I do that with a custom maker?