Search code examples
phplaravel-5.1middlewarelaravel-middleware

Does not work view function in middleware on laravel 5.1


I have middelware like this:

public function handle($request, Closure $next)
{
    if(Request::segment(1)=='test'){
        return $next($request);
    }else{
        Auth::logout();
        Session::flush();
       return view  ('login')->with(['flag'=>1]);
     }
}

and return view ('dashboard'); Dose not show login page and
Show me this error

FatalErrorException in VerifyCsrfToken.php line 101:
Call to a member function setCookie() on a non-object

Phpstorme highlight view and tooltip have this message

undefined function view more...(ctrl+f1)

When I use this command

return redirect()->guest('auth/login');

It redirect to login page, but I want pass flag to login page


Solution

  • if you want to pass flag to login page. you can try this one :

    return redirect()->guest('auth/login')->with('flag','1');