php - Laravel 5.1 Localize Factory Seeder -


i implemented new factory generate random data. want have random data in format of de_de. create faker object first, not case in laravel 5.1 new modelfactory class. how localize then?

$factory->define(app\models\aed::class, function($faker) {     return [         'owner' => $faker->company,         'street' => $faker->streetaddress,         'latitude' => $faker->latitude,         'longitude' => $faker->longitude     ]; }); 

in order change default locale used faker, easiest way override fakergenerator binding own concrete implementation:

// appserviceprovider.php $this->app->singleton(fakergenerator::class, function () {     return fakerfactory::create('nl_nl'); }); 

on top of appserviceprovider.php file add following lines:

use faker\generator fakergenerator; use faker\factory fakerfactory; 

for example, above code mean faker instances created using nl_nl provider, creating dutch faker data.

remember: has happen after databaseserviceprovider has been executed, make sure put own appserviceprovider after of laravel serviceproviders in config.php array.


Comments

Popular posts from this blog

javascript - oscilloscope of speaker input stops rendering after a few seconds -

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -