Localize Laravel 5.2 ModalFactory Faker Seeder

Posted by Andy Marthin on 11 May 2016 - 1 min read

Beberapa waktu yang lalu ketika saya lagi “belajar” laravel, saya merasa kurang puas saat mengunakan faker saat seeder data. karena faker secara default mengukan “en_US” atau standart data amerika seperti nama, alamat, no telp, dll.

ubah /app/Providers/AppServiceProvider.php

use Faker\Generator as FakerGenerator;  
use Faker\Factory as FakerFactory;

...

function register( ) {  
  $this->app->singleton(FakerGenerator::class, function () {
      return FakerFactory::create('id_ID');
  });
}

...

atau ubah /database/factories/ModelFactory.php


$faker = Faker\Factory::create('id_ID');

$factory->define(App\Employe::class, function () use ($faker){
	return[
		'name'        => $faker->name,
		'phonenumber' => $faker->phoneNumber,
		'email'       => $faker->freeEmail ,
		'address'     => $faker->streetAddress,
		'company'     => $faker->company,
	];
});

Thanks to wlkns.co