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);
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?