define(App\Models\Account::class, function (Faker $faker) { return [ 'id'=>1, ]; }); $factory->afterMaking(App\Models\Account::class, function ($service,$faker) { $country = factory(App\Models\Country::class)->make(); $service->setRelation('country',$country); $service->country_id = $country->id; });