Problem when trying to use Factories
samirgit opened this issue · 6 comments
i couldn't load database factories located in [ src/Services/{serviceName}/Database/factories ],
the Illuminate\Database\Eloquent\Factory class has a static constructor, i tried to change the factory paths by placing the below inside my ServiceProvider::register()
function
$faker = new Faker; $this->app->singleton(Factory::class, function () use ($faker) { return Factory::construct($faker, realpath(__DIR__.'/../Database/factories')); });
now the factories are available but for some reason faker stopped working properly, giving Unknown formatter "xx"
errors
What's the folder structure like for the database factories in your service ?
So i have an API service,
Structure for the factories: src/Services/Api/Database/factories/[All files here]
I assume that your custom factories under that directory are recognised by the service (reached and being read i.e. if you dd('something')
inside that file it will die and dump it), the formatter issue is considered as a Faker issue in that case. See fzaninotto/Faker#344 and fzaninotto/Faker#441
Can you confirm?