简体   繁体   English

Laravel刀片模板中的嵌套语句

[英]Nested statements in Laravel blade templating

I have the following statement(s) in my PHP and I need to make them bladey : 我的PHP中有以下语句,我需要使它们bladey

<?php

    if($project->nodes()->count()) {

        foreach($project->nodes()->get() as $node) {

            if($node->nodeable instanceof \App\Image) {

                // do something

            } else {

                // do something else

            }

        }

    }

?>

Is there a way to make it more blade-friendly ? 有没有办法使它对blade-friendlyblade-friendly Or sometimes I just have to switch back to old school PHP templating like so? 还是有时候我只需要像这样切换回老式的PHP模板? :) :)

Just replace the default php control structure syntax with blade syntax and save it with .blade.php extension. 只需将默认的php控件结构语法替换为Blade语法,然后将其保存为.blade.php扩展名即可。

View Blade syntax for control strctures for more on this 查看Blade语法以获得控制结构的更多信息

@if($project->nodes()->count())

    @foreach($project->nodes()->get() as $node)

        @if($node->nodeable instanceof \App\Image)

            // do something

        @else

            // do something else

        @endif

    @endforeach

@endif

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM