Localizing Faker in Laravel

Testing

Committed to the LaraBrain by: wjgilmore (@wjgilmore) at July 11, 2016 6:48 pm

Faker supports a wide variety of locales, but en_GB is the default. So how can you change this in your Laravel application?

Open app\Providers\AppServiceProvider.php and you'll find an empty method called register():

public function register()
{
    //
}

Change this method to look like this:

public function register()
{

    $this->app->singleton(\Faker\Generator::class, function () {
        return \Faker\Factory::create('en_US');
    });

}

Of course, you might want to change the localization to something other than en_US, so be sure to swap out this code in the above example for de_DE, es_ES, or any other of the many supported settings.