Make it easier to change the locale of Faker #398
Comments
I agree, plus it's very easy to implement with a config key. More and more we're using Faker & Factories as an easy way to quickly throw an API for prototyping frontend, and I'm pretty sure this is a pretty common use case, and we need to set the localization for this. |
I've long wished this was built in already too. I've been doing it this way, which pulls in the app.locale config setting. // tell Faker to use the app's primary locale
$this->app->singleton(\Faker\Generator::class, function () {
return \Faker\Factory::create(config('app.locale'));
}); |
Next patch you'll be able to set a faker locale in config/app.php using a |
Thanks for update @themsaid much appreciated. 😄 |
❤️ |
@themsaid I feel like that should go into a new |
Not really specifically related to testing though - I use faker in model factories and seeders to seed fake data into application for demo purposes, etc. It would be nice if it could just use |
Really helpful. I only need to add variable Or, if I want to make them more customization, just add a new varible PS : The second parameter is default value. |
@fendiseptiawan0709 GREAT. |
At the moment Faker always defaults the locale to US. It would be nice if there was some kind of way of changing it through a config/env option.
I know you can change it by completely overriding the way the faker generator singleton is registered with something like the below, but it's a bit long-winded and would be easier to change through a simple
env('FAKER_LOCALE')
option.The text was updated successfully, but these errors were encountered: