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

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度