Skip to content

Instantly share code, notes, and snippets.

@sleeping-owl
Created May 21, 2015 12:04
Show Gist options
  • Save sleeping-owl/7ccb20cb3fc1f2494911 to your computer and use it in GitHub Desktop.
Save sleeping-owl/7ccb20cb3fc1f2494911 to your computer and use it in GitHub Desktop.
<?php namespace App\Http\Middleware;
use Closure;
use Config;
use Illuminate\Http\Request;
use Session;
class AdminLocale
{
public function handle(Request $request, Closure $next)
{
if (($request->getHost() == getenv('APP_DOMAIN')) && preg_match('/\/admin/', $request->url()))
{
if ( ! Session::has('admin.locale'))
{
$locales = Config::get('translatable.locales');
Session::put('admin.locale', $request->getPreferredLanguage($locales));
}
app()->setLocale(Session::get('admin.locale'));
}
return $next($request);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment