duancashi1362 2016-10-20 06:51
浏览 28
已采纳

如何在laravel5中使用多个会话驱动程序

In Laravle5.3 I want to use multiple session driver,in the frontend I just use redis as the driver but in the backend have to use database as the driver,I tried but cant find a way to solve this problem,first I just use middleware before the session start,like

class AdminSessionDriver
{

    public function handle($request, Closure $next)
    {
        if ($request->is('admin/*')) {
            Config::set('session.driver', 'ext_database');
        }
        return $next($request);
    }
}

then in the admin route I will add the middleware, but if this when I use Multi guard,first login admin in the backend then login user in the frontend, the backend admin user is logout,but if I use the one session driver it is good,so it is a error, how to solve this question.thanks

  • 写回答

1条回答 默认 最新

  • duan1443 2016-10-24 02:12
    关注

    Here you may change the name of the cookie used to identify a session instance by ID. The name specified here will get used every time a new session cookie is created by the framework for every driver. so do

    class AdminSessionDriver
    {
    
        public function handle($request, Closure $next)
        {
            if ($request->is('admin/*')) {
                Config::set('session.driver', 'ext_database');
                Config::set('session.cookie', 'dashboard_session');
            }
            return $next($request);
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?