Property [title] does not exist on this collection instance

Richard852555發表於2020-07-09

(View: C:\phpstudy\WWW\laravel54\resources\views\user\show.blade.php)

 @foreach($posts as $post)
                        <div class="blog-post" style="margin-top: 30px">
                            <p class=""><a href="/user/{{$post->user->id}}">{{$post->user->name}}</a>{{$post->created_at->diffForHumans()}}</p>
                            <p class=""><a href="/posts/{{$post->id}}" >{{$post->title}}</a></p>


                            <p><p>{!! str_limit($post->content,100,'...')!!} </p>
                        </div>
                         @endforeach

以上才是正確的。
報錯是因為寫成了{{$posts->user->id}}。

本作品採用《CC 協議》,轉載必須註明作者和本文連結

相關文章