mpociot / laravel-test-factory-helper

Generate Laravel test factories from your existing models
935 stars 87 forks source link

Convert relation column id to closure #38

Closed ajcastro closed 5 years ago

ajcastro commented 5 years ago

Instead of

$factory->define(App\User::class, function (Faker\Generator $faker) {
    return [
        'company_id' => factory(App\Company::class)->create()->id,
    ];
});

it should be

$factory->define(App\User::class, function (Faker\Generator $faker) {
    return [
        'company_id' => function() {
              return factory(App\Company::class)->create();
         },
    ];
});
jasonmccreary commented 5 years ago

This is what it was before, which seems unnecessary.

However, there is already a PR open to readdress this in #37. So I am closing this in favor of completing the change there. Feel free to add your suggestions to it.