我有一个这样的循环:

@foreach($data as $d)
    @if(condition==true)
        {{$d}}
        // Here I want to break the loop in above condition true.
    @endif
@endforeach

如果条件满足,我想在数据显示后中断循环.

如何在laravelBlade 视图中实现?

推荐答案

From the Blade docs:

When using loops you may also end the loop or skip the current iteration:

@foreach ($users as $user)
    @if ($user->type == 1)
        @continue
    @endif

    <li>{{ $user->name }}</li>

    @if ($user->number == 5)
        @break
    @endif
@endforeach

Laravel相关问答推荐

如何更改LIVE上的Filament占位符内容?

如何让 Laravel 的 Collection 表现得像一个流?

如何在 Laravel 9 中获取带分页的订单列表?

Laravel 获取具有多对多关系的中间表数据

Laravel 验证 - 不同的属性规范

无法找到用户sail:passwd 文件中没有匹配的条目

1 子编译中的警告(使用'stats.children:true'和'--stats-children'了解更多详细信息)

Laravel Debugbar 中的 Laravel api routes路由

如何防止 Laravel 路由被直接访问(即非 ajax 请求)

如何在laravel中将数组转换为字符串?

合并两个 Eloquent 集合并删除所有重复项.

Laravel Input:all() 忽略禁用的输入

Laravel Electron邮件验证模板位置

Laravel 判断约束违规

如何将 Facebook PHP SDK 与 Laravel 5.4 集成?

Laravel:验证 json 对象

反向代理后面的 Laravel 路由

如何在不使用视图的情况下使用 Laravel 4 发送Electron邮件?

Laravel Eloquent 多态一对一?

[Vue 警告]:找不到元素:#app