微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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.

原文地址:https://www.jb51.cc/laravel/131411.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。