![](/img/trans.png)
[英]If check return true even one condition true and another false in php laravel
[英]Laravel how to check if at least one column value is true or false
如果一堆复选框中的至少一个被选中/为真,我该如何检查? 我正在使用Laravel 5.8
我现在的查询:
$preferences = DB::table("preferences")
->select('day', 'evening', 'night', 'weekend', 'full_time', 'part_time')
->where(["user_id" => request()->user()->id])
->get();
return response(['success' => true, "preferences" => $preferences]);
到目前为止这是有效的,但“只”返回一个包含每个值的数组。 像这样:
[
{
day: 0,
evening: 1,
night: 0,
weekend: 0,
full_time: 1,
part_time: 0
}
]
我需要某种价值来告诉我: is-checked: true/false
- 类似的东西。
我怎样才能做到这一点? 欢迎任何建议!
给你 go:)
array_filter($result, function($item) { return $item == true });
试试这个收藏
$collection->filter(function ($value, $key) {
return $value == true;
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.