有人可以向我解释为什么这种语法不起作用吗?
@foreach({{ ($arrayOfProducts->count()/3 == 0) ? '$arrayOfProducts as $item' : '$arrayOfProducts->chunk(($arrayOfProducts->count()/3)) as $chunk' }})
@endforeach
有人可以向我解释为什么这种语法不起作用吗?
@foreach({{ ($arrayOfProducts->count()/3 == 0) ? '$arrayOfProducts as $item' : '$arrayOfProducts->chunk(($arrayOfProducts->count()/3)) as $chunk' }})
@endforeach
If you look at the [documentation] you need to use the
@foreach
/@endforeach
in a similar way as the standard phpforeach
loop.在代码中,实际上是将字符串作为循环的参数传递。如果要使其工作,则需要在项目数组上传递条件,然后对其进行循环。
您需要学习基本语法。
This would work just fine, behind the scenes it's just basic PHP
foreach
loop, and{{ }}
is justecho
, also try to keep that conditional logic in your controller for more readable code.