如何在拉拉维尔叶片视图中打破前方循环?
我有一个这样的循环:
@foreach($data as $d)
@if(condition==true)
{{$d}}
// Here I want to break the loop in above condition true.
@endif
@endforeach
如果满足条件,我想在数据显示后中断循环。
如何在拉拉维尔叶片视图中实现?
我有一个这样的循环:
@foreach($data as $d)
@if(condition==true)
{{$d}}
// Here I want to break the loop in above condition true.
@endif
@endforeach
如果满足条件,我想在数据显示后中断循环。
如何在拉拉维尔叶片视图中实现?
来自 Blade 文档:
使用循环时,您还可以结束循环或跳过当前迭代:
@foreach ($users as $user)
@if ($user->type == 1)
@continue
@endif
<li>{{ $user->name }}</li>
@if ($user->number == 5)
@break
@endif
@endforeach
你可以像这样打破
@foreach($data as $d)
@if($d === "something")
{{$d}}
@if(condition)
@break
@endif
@endif
@endforeach