laravel 登录laravel 尝试获取非对象的属性

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/45209640/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 16:20:31  来源:igfitidea点击:

Login laravel Trying to get property of non-object

phplaravel

提问by Lluís Puig Ferrer

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.

我访问 /admin 并重定向到 /admin/login(这是正常的,因为我没有登录)但我看不到我的视图 /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

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;

    }
}

回答by Maraboc

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

您需要做的就是添加,return $next($request);因为它将适用于 $guard 女巫的默认值是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 :)
}