//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);
}}
网友评论