在 app/Providers/AppServiceProvider.php 的boot()方法加上:
\Carbon\Carbon::setLocale('zh');
#2. Model Factory 生成本地化数据 在 AppServiceProvider.php boot() 方法内加入如下内容:
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Faker\Generator as FakerGenrator;
use Faker\Factory as FakerFactory;
class AppServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
$this->app->singleton(FakerGenrator::class,function(){
return FakerFactory::create('zh_CN');
});
}
/**
* Register any application services.
*
* @return void
*/
public function register()
{
//
}
}
注意类开头的 use Faker\Generator as FakerGenrator; ** use Faker\Factory as FakerFactory;** Faker 支持的其他语言,参见 https://github.com/fzaninotto/Faker