我在显示刀片模板中的集合时遇到了问题。在刀片模板中显示Laravel集合
$comments = Comment::all();
return view('comments/index')->with(compact('comments'));
刀片的代码是:
@isset($comments)
@foreach($comments as $comment)
<div>
<p>
<a href="{{ url('comments/', $comment->id) }}"><{{ $comment->commentor }}</a>
</p>
</div>
<hr>
@endforeach
@endisset
@empty($comments)
<div>
<p>There were no comments available.</p>
{{ $comments }}
</div>
@endempty
但不知道如何获取数据到模板渲染。它只是呈现一个空白页。
有什么错误? – JYoThI
如果整个页面都是空白的,这听起来像是一个PHP错误。检查你的apache error.log – Brad
也我觉得评论/索引应该是comments.index – Brad