Skip to content

Instantly share code, notes, and snippets.

@Aslam97
Created October 11, 2020 14:20
Show Gist options
  • Save Aslam97/57e1d2bcec53e20e8ef8d16e65f14cf8 to your computer and use it in GitHub Desktop.
Save Aslam97/57e1d2bcec53e20e8ef8d16e65f14cf8 to your computer and use it in GitHub Desktop.
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Session;
class LangMiddleware
{
/**
* lang
*
* @var mixed
*/
private $lang;
/**
* __construct
*
* @return void
*/
public function __construct()
{
$this->lang = Session::get('locale');
}
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if (Session::has('locale')) {
App::setLocale($this->lang);
}
return $next($request);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment