登录laravel试图获取非对象的属性 [英] Login laravel Trying to get property of non-object

查看:82
本文介绍了登录laravel试图获取非对象的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我访问/admin,并且重定向到/admin/login(这很正常,因为我没有登录),但是我看不到/admin/login的视图.

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.

我收到此错误:

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

如果需要某些控制器的代码或其他代码,请编写.

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

谢谢

行错误:

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

RedirectIfAuthenticated.php上的处理函数

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;

    }
}

推荐答案

所有您需要做的就是添加return $next($request);,因为它适用于默认值为$ guard witch为null

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 :)
}

这篇关于登录laravel试图获取非对象的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆