post 模型和 user 模型的视图层的一个语法问题
@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
{{$post->user->id}}
分别有posts模型和User模型,{{$post->user->id}}这样的写法是因为user模型定义了hasmany 和posts模型的关联吗? 为什么用dd()函数打印不出来?
推荐文章: