美文网首页
laravel 实现子域名或参数多语言

laravel 实现子域名或参数多语言

作者: 龙权 | 来源:发表于2016-05-18 18:17 被阅读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); 
    }}
    

    相关文章

      网友评论

          本文标题:laravel 实现子域名或参数多语言

          本文链接:https://www.haomeiwen.com/subject/stmwrttx.html