laravel 实现子域名或参数多语言
2016-05-18 本文已影响920人
龙权
//routes.php
$route->group(['domain' => '{lang}.do.com'], function(){});
// middleware
\Route::current()->getParameter('lang');
<?php
namespace AppHttpMiddleware;
use Closure;
use IlluminateSupportFacadesApp;
class LangMiddleware{
public function handle($request, Closure $next) {
$url_array = explode('.', parse_url($request->url(), PHP_URL_HOST));
$subdomain = $url_array[0];
$languages = ['en', 'de'];
if (in_array($subdomain, $languages)) {
App::setLocale($subdomain);
}
return $next($request);
}}