该whereBetween
方法验证列的值是否在两个值之间。
$from = date('2018-01-01');$to = date('2018-05-02');Reservation::whereBetween('reservation_from', [$from, $to])->get();在某些情况下,您需要动态添加日期范围。根据@Anovative的评论,您可以执行以下操作:
Reservation::all()->filter(function($item) { if (Carbon::now->between($item->from, $item->to) { return $item; }});如果您想添加更多条件,则可以使用
orWhereBetween。如果您想排除日期间隔,则可以使用
whereNotBetween。
Reservation::whereBetween('reservation_from', [$from1, $to1]) ->orWhereBetween('reservation_to', [$from2, $to2]) ->whereNotBetween('reservation_to', [$from3, $to3]) ->get();其他有用的where子句:
whereIn,
whereNotIn,
whereNull,
whereNotNull,
whereDate,
whereMonth,
whereDay,
whereYear,
whereTime,
whereColumn,
whereExists,
whereRaw。



