Laravel 如何检查至少一列值是真还是假

Laravel how to check if at least one column value is true or false

如果一堆复选框中至少有一个是 checked/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]);

到目前为止这是可行的,但是“只有”returns 一个包含每个值的数组。像这样:

[
  {
    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

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