laravel多语言laravel-lang


安装laravel-lang

composer require overtrue/laravel-lang
php artisan lang:publish zh_CN
php artisan make:middleware AcceptLanguage

配置laravel-lang

config/app.php

// Illuminate\Translation\TranslationServiceProvider::class,
\Overtrue\LaravelLang\TranslationServiceProvider::class,

app/Http/Middleware/AcceptLanguage.php

// 获取前端首选语言,存在则更新
$local = $request->getPreferredLanguage();
$local && app()->setLocale($local);