stoneworld stoneworld - 1 month ago 6
PHP Question

how to use multiple session driver in 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

Answer

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);
    }
}
Comments