laravel / lumen-framework

The Laravel Lumen Framework.
https://lumen.laravel.com
MIT License
1.48k stars 419 forks source link

faker_locale option is not working #989

Closed Lin07ux closed 5 years ago

Lin07ux commented 5 years ago

Description:

The faker_locale option in config/app.php is not working when i use factory() method to generate data in Lumen 5.8 or 6.2.

Steps To Reproduce:

Firt, I set the faker_locale option in config/app.php:

'faker_locale' => 'zh_CN'

Then, I define a factory like this:

$factory->define(Subject::class, function (Faker $faker) {
    return [
        'name' => $faker->name,
    ];
});

I used this factory in a seeder. When I run the seeder, I got a Subject whose name attribute is in English, eg. Alexane Hirthe, not the Chinese name I excepted.

However, when I modify part code in the Illuminate\Database\DatabaseServiceProvider::registerEloquentFactory(), I get the correct result:

$this->app->singleton(FakerGenerator::class, function ($app) {
    // new code
    $this->app->configure('app');

    return FakerFactory::create($app['config']->get('app.faker_locale', 'en_US'));
});
driesvints commented 5 years ago

This is currently not implemented in Lumen but you can send in a PR if you want.

Here's the Laravel implementation: https://github.com/laravel/framework/blob/ffdc4e590f1a45190984a9770051281b7ee28d8d/src/Illuminate/Database/DatabaseServiceProvider.php#L77-L79