答案 0 :(得分:0)
当您要访问的属性不存在时会发生此错误,因此您应该检查属性isset
以下是示例
@if (!is_null($news_comment->user))
<div class="well">
<a href="{{action('ProfileController@show', [$news_comment->user->id, $news_comment->user->name])}}">{!! $news_comment->user->name!!}</a>
{{$news_comment->comments}}<br/>
{{$news_comment->created_at}}
</div>
@endif
或强>
@if (isset($news_comment->user->id) && isset($news_comment->user->name))
<div class="well">
<a href="{{action('ProfileController@show', [$news_comment->user->id, $news_comment->user->name])}}">{!! $news_comment->user->name!!}</a>
{{$news_comment->comments}}<br/>
{{$news_comment->created_at}}
</div>
@endif
答案 1 :(得分:0)
尝试使用()
上的user
<a href="{{action('ProfileController@show', [$news_comment->user()->id, $news_comment->user()->name])}}">{!! $news_comment->user()->name!!}</a>
而不是:
<a href="{{action('ProfileController@show', [$news_comment->user->id, $news_comment->user->name])}}">{!! $news_comment->user->name!!}</a>