我必须管理房屋租赁的预订,当我进行新的预订时,开始日期和结束日期应该是免费的。
例如,如果我为客户预订了9月23日至9月28日的预订,则无法在此日期内创建另一个预订。我需要一个雄辩的查询,可以检查started_at和ends_at (的形式)没有包括在已经存在的日期之间
发布于 2021-11-27 13:19:47
我想我找到了一个解决方案:
$bookings = DB::table('bookings')
->where(function ($q) use ($start, $end) {
$q->where('started_at', '>=', $start)
->where('started_at', '<=', $end);
})
->orWhere(function ($q) use ($start, $end) {
$q->where('ends_at', '>=', $start)
->where('ends_at', '<=', $end);
})
->orWhere(function ($q) use ($start, $end) {
$q->where('started_at', '<', $start)
->where('ends_at', '>', $end);
})
->count();https://stackoverflow.com/questions/70135004
复制相似问题