Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I access to /admin and i get the redirect to /admin/login (that's normal, cause i'm not logged) but i can't see my view /admin/login.

I get this error:

Trying to get property of non-object
in VerifyCsrfToken.php (line 156)

If need code of some controller or something, write it please.

Thanks

Lines error:

$response->headers->setCookie(
        new Cookie(
            'XSRF-TOKEN', $request->session()->token(), Carbon::now()-
>getTimestamp() + 60 * $config['lifetime'],
            $config['path'], $config['domain'], $config['secure'], 
 false
        )
    );

Handler function on RedirectIfAuthenticated.php

    public function handle($request, Closure $next, $guard = null)
{

    switch($guard){
        case 'admin':
            if (Auth::guard($guard)->check()) {
                return redirect()->route('admin.dashboard');
            }
        break;

        default:
        if (Auth::guard($guard)->check()) {
            return redirect('/');
        }
        break;

    }
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
346 views
Welcome To Ask or Share your Answers For Others

1 Answer

All you need to do is add return $next($request); because it will work for the requests with the default value of $guard witch is null

public function handle($request, Closure $next, $guard = null)
{

    switch($guard){
        case 'admin':
            if (Auth::guard($guard)->check()) {
                return redirect()->route('admin.dashboard');
            }
        break;

        default:
            if (Auth::guard($guard)->check()) {
                return redirect('/');
            }
        break;
    }
    return $next($request); //<-- this line :)
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...