我正在创建报告页面,我想做的是从特定日期到具体日期显示报告.我当前的代码是:
$now = date('Y-m-d'); $reservations = Reservation::where('reservation_from',$now)->get();
这样做是从表中选择*,其中reservation_from = $现在.我在这里有一个查询,但我不知道如何将它转换成雄辩的查询.这是我的代码:
SELECT * FROM table WHERE reservation_from BETWEEN '$from' AND '$to
The
whereBetween
method verifies that a column’s value is between
two values.
尝试:
$reservations = Reservation::whereBetween('reservation_from',[$from,$to])->get();
如果你想添加更多的条件,你可以使用或WhereBetween.
$reservations = Reservation::whereBetween('reservation_from',[$from_from,$to_from]) ->orWhereBetween('reservation_to',[$from_to,$to_to]) ->get();
你应该知道:whereNotBetween,whereIn,whereNotIn,whereNull,whereNotNull