Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/245.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php laravel获取经过身份验证的用户_Php_Laravel_Laravel 4 - Fatal编程技术网

Php laravel获取经过身份验证的用户

Php laravel获取经过身份验证的用户,php,laravel,laravel-4,Php,Laravel,Laravel 4,当用户登录时,我执行以下操作: $remember_me = true; if(Input::has('remember_me')){ $remember_me = true; }else{ $remember_me = false; } if (Auth::attempt(array('username' => Input::get('username'), 'passwo

当用户登录时,我执行以下操作:

 $remember_me = true;
        if(Input::has('remember_me')){
            $remember_me = true;
        }else{
            $remember_me = false;
        }

        if (Auth::attempt(array('username' => Input::get('username'), 'password' => Input::get('password')), $remember_me))
        {
            echo Auth::user()->picture;exit;
        }
        return Redirect::back()->withInput()->withErrors(Input::all())->with(array('errorMessage'=>'Username or password is not correct'));
如你所见,我正在打印图片的值,它是正确的。因此,用户已经登录,我应该能够在另一个控制器中这样呼叫他/她

$user = Auth::user();
echo $user->firstName;exit
但我得到:

ErrorException
Trying to get property of non-object
我已经把“记住我”设定为真了。我应该怎么做才能使用经过身份验证的用户

非常感谢
  • 绝不能退出Laravel中的函数
  • 重要的是你总是
    返回
    一些东西

  • 原因是,Laravel处理一些函数的最终实现,设置为设置标题、cookies等。当您退出时,您会缩短此过程,因此Laravel无法完成某些函数,因此,您将得到错误。

    永远不要退出
    -您应该始终在Laravel中返回一些内容,以便正确设置标题。这可能是会话错误,也可能是…@Shift Exchange好的,我将尝试重定向到调用$user->firstName的路由并进行更新you@TheShiftExchange好极了,它很管用,请问,为什么退出会导致这个问题?只是为了了解发生了什么on@TheShiftExchange请写一个答案接受它。谢谢你能检查一下我的问题吗?提前谢谢