Create just one related model for feature test

Posted 10 months ago by RossUK

If I am writing a test that contains both a user model and a post model each has an associated Model Factory. I know I can do the following to create a collection of related records but how do I create just one of each for use during a feature test.

$users = factory(App\User::class, 3)
           ->each(function ($u) {

for example

$customer = factory('App\User')->create()

// then add a single post to this user

Many Thanks

Please sign in or create an account to participate in this conversation.