Skip to content

Instantly share code, notes, and snippets.

@remoblaser
Created May 30, 2016 11:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save remoblaser/09b1c4feb58159084b473acda904d973 to your computer and use it in GitHub Desktop.
Save remoblaser/09b1c4feb58159084b473acda904d973 to your computer and use it in GitHub Desktop.
Language Middleware for Laravel
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Foundation\Application;
use Illuminate\Http\Request;
use Illuminate\Routing\Redirector;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Session;
class Language {
public function handle($request, Closure $next)
{
$activeLanguage = Session::get('applocale'); // Get current Language based on your structure and idea
if ($activeLanguage && in_array($activeLanguage, Config::get('app.locales'))) {
App::setLocale($activeLanguage);
}
return $next($request);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment