Laravel 5.8 汽车租赁项目Laravel中日期和时间段之间的可用或不可用汽车
我正在尝试使用Laravel 5.8构建租车预订流程 我想显示所有可用的汽车,但在特定的时间段内,Laravel 5.8 汽车租赁项目Laravel中日期和时间段之间的可用或不可用汽车,laravel-5.8,Laravel 5.8,我正在尝试使用Laravel 5.8构建租车预订流程 我想显示所有可用的汽车,但在特定的时间段内,预订表中找不到汽车 取车日期和取车日期随时间变化 我现在有什么? 我有取车日期,取车时间还有下车日期,下车时间和车辆id 当我的取车日期和下车日期相同时,我能够找出哪些车可用和不可用 但是我的问题是放弃日期 让我详细解释一下: 我想我正在预订房间,我的 提货时间=“23:45:00”和提货日期=“2020-09-05” 提货时间=“04:28:00”和提货日期=“2020-09-06” 注:pic
预订
表中找不到汽车
取车日期
和取车日期
随时间变化
我现在有什么?
我有取车日期
,取车时间
还有下车日期
,下车时间
和车辆id
当我的取车日期
和下车日期
相同时,我能够找出哪些车可用和不可用
但是我的问题是放弃日期
让我详细解释一下:
我想我正在预订房间,我的
提货时间=“23:45:00”和提货日期=“2020-09-05”提货时间=“04:28:00”和提货日期=“2020-09-06”
注:
pick\u-up\u-date
,drop\u-off\u-date
数据库数据类型为:date
和pick\u-up\u-time
,drop\u-off\u-time
数据库数据类型为time
当取车日期
和下车日期
与时隙检查不同时,如何进行查询?$found=Reservation::query()
$found= Reservation::query()
->where('vehicle_id', $id)
->where(function($exits) use ($start_timestamp,$end_timestamp)
{
$exits->where(function ($findConflict) use ($start_timestamp,$end_timestamp) {
$findConflict->whereBetween('start_timestamp',[$start_timestamp,$end_timestamp])
->orWhereBetween('end_timestamp',[$start_timestamp,$end_timestamp]);
})
->orWhere(function($middleClause) use ($start_timestamp,$end_timestamp) {
$middleClause
->where('start_timestamp','<=',$end_timestamp)
->where('end_timestamp','>=',$start_timestamp);
});
})
->get();
if ($found->count()>0){
echo $available = 0;
}else{
echo $available = 1;
}
->其中(‘车辆识别号’,$id)
->其中(函数($exits)使用($start\u timestamp,$end\u timestamp)
{
$exits->where(函数($findConflict)use($start\u timestamp,$end\u timestamp){
$findConflict->whereBetween('start\u timestamp',[$start\u timestamp,$end\u timestamp])
->或两者之间('end_timestamp',[$start_timestamp,$end_timestamp]);
})
->orWhere(函数($middleClause)使用($start\u timestamp,$end\u timestamp){
美元中间条款
->其中('start_timestamp','=',$start_timestamp);
});
})
->get();
如果($found->count()>0){
echo$available=0;
}否则{
echo$available=1;
}
原始sql:
从
预订中选择*,其中
车辆id=您的车辆id和((
开始时间戳介于您的开始日期时间和结束日期时间之间,或
结束时间戳介于开始日期时间和结束日期时间之间)或(
开始时间戳=开始日期时间))
你在用碳吗?是的,我在用@斯马特拉哈特