Laravel 如何在刀片模板中使用集合功能?
我尝试在Blade模板中控制输出流,为此我在模板中使用收集功能:Laravel 如何在刀片模板中使用集合功能?,laravel,laravel-5.2,Laravel,Laravel 5.2,我尝试在Blade模板中控制输出流,为此我在模板中使用收集功能: @if(count($item->images)) @if($item->images->count() > 1 && $item->images->count() < 3) {{$chunk = $item->images->forPage(0, 1)}} // It displays $chunk like as object (str
@if(count($item->images))
@if($item->images->count() > 1 && $item->images->count() < 3)
{{$chunk = $item->images->forPage(0, 1)}} // It displays $chunk like as object (string) in template
@endif
@endif
你不能这么做吗
@if(count($item->images))
@if($item->images->count() > 1 && $item->images->count() < 3)
@foreach($item->images->forPage(0, 1) as $image)
// Show here
@endforeach
@endif
@endif
@if(计数($item->images))
@如果($item->images->count()>1&&$item->images->count()<3)
@foreach($item->images->forPage(0,1)作为$image)
//在这里展示
@endforeach
@恩迪夫
@恩迪夫
你不能这样做吗
@if(count($item->images))
@if($item->images->count() > 1 && $item->images->count() < 3)
@foreach($item->images->forPage(0, 1) as $image)
// Show here
@endforeach
@endif
@endif
@if(计数($item->images))
@如果($item->images->count()>1&&$item->images->count()<3)
@foreach($item->images->forPage(0,1)作为$image)
//在这里展示
@endforeach
@恩迪夫
@恩迪夫
与
<?php echo some php code; ?>
<?php some php code; ?>
不一样
<?php echo some php code; ?>
<?php some php code; ?>
您可以做的是将信息传递到循环:
@if(count($item->images))
@if($item->images->count() > 1 && $item->images->count() < 3)
@foreach($item->images->forPage(0, 1) as $image)
// do stuff
@endforeach
@endif
@endif
@if(计数($item->images))
@如果($item->images->count()>1&&$item->images->count()<3)
@foreach($item->images->forPage(0,1)作为$image)
//做事
@endforeach
@恩迪夫
@恩迪夫
或者您可以使用radic/blade extensions()等软件包,并使用@set()
设置变量
或者你可以在模板中使用普通的PHP,但这当然不是很好
与
<?php echo some php code; ?>
<?php some php code; ?>
不一样
<?php echo some php code; ?>
<?php some php code; ?>
您可以做的是将信息传递到循环:
@if(count($item->images))
@if($item->images->count() > 1 && $item->images->count() < 3)
@foreach($item->images->forPage(0, 1) as $image)
// do stuff
@endforeach
@endif
@endif
@if(计数($item->images))
@如果($item->images->count()>1&&$item->images->count()<3)
@foreach($item->images->forPage(0,1)作为$image)
//做事
@endforeach
@恩迪夫
@恩迪夫
或者您可以使用radic/blade extensions()等软件包,并使用@set()
设置变量
或者你可以在模板中使用普通的PHP,但这当然没有那么好。我无法理解你想要实现什么。在我尝试在同一个模板中迭代结果之后,我可以尝试使用模板中的函数forPage:{$chunk=$item->images->forPage(0,1)
,该模板位于{}之间
是用它们之间的代码输出打印出来的。请检查我的答案,这就是你的意思吗?我无法理解你想要实现什么。请你详细说明一下,我可以尝试在模板中使用函数forPage:{$chunk=$item->images->forPage(0,1)
在我尝试在同一个模板中迭代结果$chunk
之后,您在{}之间放置了什么
是用它们之间的代码输出打印出来的。请检查我的答案,这是你的意思吗?是的,它可以工作,但我尝试在模板的末尾使用一个循环来实现更优雅的效果。这与我认为的类似,虽然你也可以使用php
标记,但它不是标准的。是的,它可以工作,但我尝试在模板末尾的一个循环。这与我认为的类似,虽然您也可以使用php
标记,但它不是标准的