在 Laravel 中构造以下数据库查询的最佳方法是什么

What is the best way to structure the following database query in Laravel

我在构建满足以下条件的查询时遇到了问题。

开始日期为 today/future 或 0000/00/00
结束日期为 today/future 或 0000/00/00
其中观看次数超过 3

这是我目前所拥有的。

$users = DB::table('videos')
    ->where('start' <= date('Y-m-d'));
    ->orwhere('start' = "0000:00:00 0000");
    ->where('end' > date('Y-m-d'));
    ->orwhere('end' = "0000:00:00 0000");
    ->where('views' => "3");
    ->get();

如有任何建议,我们将不胜感激,谢谢!

您想将 advanced where 与参数分组一起使用:

$users = DB::table('videos')
    ->where(function($q) {
        $q->where('start', '<=', date('Y-m-d'))
          ->orWhere('start', '=', "0000:00:00 0000");
    })
    ->where(function($q) {
        $q->where('end', '>', date('Y-m-d'))
          ->orWhere('end', '=', "0000:00:00 0000");
    })
    ->where('views', '>', 3)
    ->get();