加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

php – Laravel雄辩的日期范围

发布时间:2020-12-14 19:43:52 所属栏目:大数据 来源:网络整理
导读:我正在创建报告页面,我想做的是从特定日期到具体日期显示报告.我当前的代码是: $now = date('Y-m-d');$reservations = Reservation::where('reservation_from',$now)-get(); 这样做是从表中选择*,其中reservation_from = $现在.我在这里有一个查询,但我不知
我正在创建报告页面,我想做的是从特定日期到具体日期显示报告.我当前的代码是:
$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.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读