Search code examples
laravelsessionrouteslaravel-artisan

php artisan route:list RuntimeException Session store not set on request


When I check the route list by command form doc:

php artisan route:list //RuntimeException:  Session store not set on request.

I found it should be better use helper function session() instead of $request->session() in Controller __contract function.

class SomeController extends Controller
{
    public function __construct(Request $request)
    {
        //use $request->session()->has($var) will occur the exception as this post said.
        if (session()->has($var)) {          
        //do something;
    }
}

}


Solution

  • Use session() instead $request->session() in controller, like:

    class SomeController extends Controller
    {
        public function __construct(Request $request)
        {
            //use $request->session()->has($var) will occur the exception as this post said.
            if (session()->has($var)) {          
            //do something;
            }
        }
    }