How to pass arguments to Laravel factories?

The attributes you pass to the create function will be passed into your model definition callback as the second argument.


In your case you don’t even need to access those attributes, since they’ll automatically be merged in:

$business = factory(App\Business::class)->create();

factory(App\User::class, 5)->create([
    'business_id' => $business->id,
]);

Adapt this to your needs.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)