试图获取非对象错误的属性

时间:2017-07-18 06:53:46

标签: laravel

我有这个错误试图获取非对象的属性

(View: C:\xampp\htdocs\DigitalStudio\resources\views\welcome.blade.php)
in b1747510b3c408d907ba1958669ebd058ad57227.php (line 101)

,指出的是这一行

<img src="/uploads/avatars/{{ Auth::User()->avatar }}" class="img-circle person" alt="Random Name" width="255" height="255">

我的代码中有错误或错误吗?在我的其他页面配置文件中,这是我的个人资料页面图片标记

 <img src="/uploads/avatars/{{ Auth::User()->avatar }}" style="width:150px; height:150px; float:left; border-radius:50%; margin-right:25px;">

1 个答案:

答案 0 :(得分:1)

您应该始终检查用户是否经过身份验证:

@if (auth()->check())
    <img src="/uploads/avatars/{{ auth()->user()->avatar }}" style="width:150px; height:150px; float:left; border-radius:50%; margin-right:25px;">
@else
    Please login
@endif