vendredi 17 mai 2019

Laravel 5.8 factory states Unable to locate factory with name [default] [CLASS]

I'm trying to create two different sets of seeders and attempting to use Laravel's factory states to specify different factories for each seeder. Here is an basic example of a BoopieFactory:

$factory
    ->state(App\Models\Boopie::class, 'one_flavored', function (Faker $faker) {
        return [];
    });

$factory
    ->state(App\Models\Boopie::class, 'two_flavored', function (Faker $faker) {
        return ['something different'];
    });

I was then under the assumption that I could call either factory(\App\Models\Boopie::class, 25)->states('one_flavored')->create(); or factory(\App\Models\Boopie::class, 25)->states('two_flavored')->create();. These result in the above mentioned Unable to locate factory with name [default] [App\Models\Boopie]. error. Am I missing something small here, or is this just a complete mis-understanding of factory states? Or do I also still need to define the factory first and then chain state on? Laravel's docs are usual great, but lack in this department. Thanks in advance 😀!



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire