Iro*_*j18 0 php foreach templates if-statement laravel
我已经看到“没有帖子”,如果它们可以作为评论,即使 URL 是有效的属性。我在 laravel.com 上发现 @if 和 @else 中不乏信息或示例。http://laravel.com/docs/4.2/templates#other-blade-control-structures。
这是我的代码
@if ($post->comments)
<div class="text-center jumbotron">
<h1 style="color:red;">There are no posts</h1>
</div>
@endif
@foreach ($post->comments as $comment)
<div class="row">
<div class="col-xs-12">
{{{ $comment->user->name }}}:
<blockquote>{{{ $comment->text}}}</blockquote>
</div>
</div>
@endforeach
Run Code Online (Sandbox Code Playgroud)
但是我已经尝试更改 @if ($post->comments as $comment) 说“语法错误,意外的 'as' (T_AS)” 你有什么想法来解决它吗?
或者你可以这样使用刀片的@forelse
环
@forelse($post->comments as $comment)
<div class="row">
<div class="col-xs-12">
{{{ $comment->user->name }}}:
<blockquote>{{{ $comment->text}}}</blockquote>
</div>
</div>
@empty
<div class="text-center jumbotron">
<h1 style="color:red;">There are no posts</h1>
</div>
@endforelse
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
3204 次 |
最近记录: |