<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Session;
class Language
{
/**
* @param $request
* @param Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if (Session::has('language') AND in_array(Session::get('language'), Config::get('app.locales'))) {
App::setLocale(Session::get('language'));
}
else { // This is optional as Laravel will automatically set the fallback language if there is none specified
App::setLocale(Config::get('app.locale'));
}
return $next($request);
}
}
配置app/http/middleware/kernel.php 添加Language

基本上就是这样了,试试看,希望可以对你有帮助。告辞!
以上这篇Laravel5.5 动态切换多语言的操作方式就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持黑区网络。
