27 lines
717 B
PHP
27 lines
717 B
PHP
<?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);
|
|
}
|
|
}
|