小编Iro*_*j18的帖子

如何用 @foreach 和 @if 做 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)” 你有什么想法来解决它吗?

php foreach templates if-statement laravel

0
推荐指数
1
解决办法
3204
查看次数

标签 统计

foreach ×1

if-statement ×1

laravel ×1

php ×1

templates ×1