Authentication Auth::user()->非对象

Authentication Auth::user()->非对象,authentication,laravel,Authentication,Laravel,我试图从数据库中检索用户的名字,所以我在provider.php控制器中尝试了类似的操作,但浏览器错误显示试图获取非对象的属性 $provider = Auth::user()->email; return View::make('providers.account') ->with('title', 'Account') ->with('provider', $provider); 有什

我试图从数据库中检索用户的名字,所以我在provider.php控制器中尝试了类似的操作,但浏览器错误显示试图获取非对象的属性

$provider = Auth::user()->email;
    return View::make('providers.account')
                    ->with('title', 'Account')
                    ->with('provider', $provider);

有什么帮助吗?

您需要检查用户是否已登录:

if (Auth::check())
{
$provider = Auth::user()->email;
    return View::make('providers.account')
                    ->with('title', 'Artsgap Account')
                    ->with('provider', $provider);
} 

否则,它将返回对象没有返回的错误;不存在,因为没有登录用户

如果您试图获取登录用户的信息,请使用Ben Dubuisson的答案

如果要尝试获取指定用户的信息,请执行以下操作:

$provider = User::find($id)->email;

您介意添加完整的错误堆栈吗。它通常可以在app/storage/logs/log-apache2handler-{today}中找到?您是否应该在之前进行检查?请尝试使用if Auth::check{//用户已登录…}Oh-.-不,我没有登录,但如何从数据库检索数据。