php – Laravel雄辩的日期范围

前端之家收集整理的这篇文章主要介绍了php – Laravel雄辩的日期范围前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在创建报告页面,我想做的是从特定日期到具体日期显示报告.我当前的代码是:
$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

Laravel docs about where.

猜你在找的Laravel相关文章