在刀片模板中显示Laravel集合

在刀片模板中显示Laravel集合,laravel,laravel-5,laravel-blade,Laravel,Laravel 5,Laravel Blade,我在刀片模板中显示集合时遇到问题 $comments = Comment::all(); return view('comments/index')->with(compact('comments')); 刀片的代码为: @isset($comments) @foreach($comments as $comment) <div> <p> <a href="{{ url('comments/', $comm

我在刀片模板中显示集合时遇到问题

$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

但不确定如何获取要在模板中渲染的数据。它只是呈现一个空白页。

使用点符号来引用视图文件夹结构,即查看“comments.index”。这表示文件resources/views/comments/index.blade.php。用这个

@forelse ($comments as $comment)
    <div>
        <p>
            <a href="{{ url('comments/', $comment->id) }}">{{ $comment->commentor }}</a>
        </p>
    </div>
    <hr/>
@empty
    <div>
        <p>There were no comments available.</p>
    </div>
@endforelse
改用这个:

$comments = Comment::all();

return view('comments.index')->with(compact('comments'));

是否有任何错误?如果整个页面为空,则听起来像是PHP错误。检查你的apache错误。我还认为注释/索引应该是comments.indexNo没有错误。并返回注释集合。我在上面做了一个dd,收集了一些评论,好的。它只是在刀片模板上,它不会显示。