php - 这是获取 Laravel 中可预订房间列表的功能。谁能帮我弄清楚查询有什么问题?
问题描述
2021-09-29 09:00 至 2021-09-29 10:00 预订房间时,房间应在 2021-09-29 10:00 开始预订,但在这种情况下,房间可用从 2021 年 9 月 29 日 10:01 开始。
public function searchRoom(Request $request)
{
$rooms = null;
if($request->filled(['start_time', 'end_time', 'capacity'])) {
$times = [
Carbon::parse($request->input('start_time')),
Carbon::parse($request->input('end_time')),
];
$rooms = Room::where('capacity', '>=', $request->input('capacity'))
->whereDoesntHave('events', function ($query) use ($times) {
$query->whereBetween('start_time', $times)
->orWhereBetween('end_time', $times)
->orWhere(function ($query) use ($times) {
$query->where('start_time', '<', $times[0])
->where('end_time', '>', $times[1]);
});
})
->get();
}
return view('admin.bookings.search', compact('rooms'));
}
解决方案
推荐阅读
- javascript - 如何转义动态文本
tag inside header using Nuxt JS?</h1> <div id="body"><p>I have integrated WordPress API with a Nuxt based website. It is using below code to show blog Post title fetched from wordpress.</p> <pre><code>h - ios - 基于IOS swift中的复选框状态禁用/启用返回键
- java - java中的"Paths.get("").toAbsolutePath().toString()"和"System.getProperty("user.dir")"有什么区别?
- android-studio - 浏览时未显示 Android Studio Marketplace 中的插件
- c# - 如何再次从 Bot Framework v4 获取自适应卡片列表?
- c# - 只有assignment、call、increment、decrement、await和new对象表达式可以作为语句错误C#
- python - 字节格式的时间数据不匹配
- node.js - 由于 MongoNetworkError 和内存泄漏问题,Node.js 服务器无响应且不稳定
- django - 如何通过 DJANGO REST API 从模型中检索和创建数据?
- python - 从文件内的字符串中将列表附加到列表中