Created
May 30, 2016 11:09
-
-
Save remoblaser/09b1c4feb58159084b473acda904d973 to your computer and use it in GitHub Desktop.
Language Middleware for Laravel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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