Laravel如何检查至少一列值是true还是false

问题描述

如何检查一堆复选框中的至少一个是否为true?我正在使用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]);

到目前为止,这是可行的,但是“ only”将返回带有每个值的数组。像这样:

[
  {
    day: 0,evening: 1,night: 0,weekend: 0,full_time: 1,part_time: 0
  }
]

我需要一种能告诉我的价值:is-checked: true/false-类似的东西。

我该如何实现?欢迎任何建议!

解决方法

您在这里:)

array_filter($result,function($item) { return $item == true });
,

在收藏中尝试

$collection->filter(function ($value,$key) {
    return $value == true;
});