Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Login laravel Trying to get property of non-object

Tags:

php

laravel

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;

    }
}
like image 550
Lluís Puig Ferrer Avatar asked Jul 20 '17 08:07

Lluís Puig Ferrer


1 Answers

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 :)
}
like image 167
Maraboc Avatar answered Nov 06 '22 22:11

Maraboc