Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- protected $languages = ['en', 'ar'];
- public function handle($request, Closure $next)
- {
- Session::has('applocale') ? Session::get('applocale') : Session::set('applocale', 'en');
- if (in_array(Session::get('applocale'), $this->languages)) {
- $lang = Session::get('applocale');
- Session::set('applocale', $lang);
- App::setLocale($lang);
- } else {
- Session::set('applocale', 'en');
- App::setLocale('en');
- }
- return $next($request);
- }
- Route::group(['middleware' => ['web', 'language']], function () {
- // app routes
- });
- Route::group(['middleware' => ['web', 'language']], function () {
- Route::group(['prefix' => '{lang}'], function () {
- // app routes
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement