在汽车租赁项目 Laravel 的日期和时间段之间可用或不可用的汽车
Car available or unavalible between date and time slot in car rental Project Laravel
我正在尝试使用 Laravel 5.8 构建租车预订流程。
我想显示所有可用的汽车,而在特定的 Reservation
table 之间找不到汽车
pick_up_date
和 drop_off_date
随着时间的推移。
我现在有什么?
我有pick_up_date
、pick_up_time
还有drop_off_date
、drop_off_time
还有vehicle_id
.
当我的 pick_up_date
和 drop_off_date
相同时,我能够弄清楚哪些车可用和不可用。
但我的问题是 drop_off_date
。
让我详细解释一下:
猜猜我正在尝试预订和我的
pick_up_time = "23:45:00" AND pick_up_date='2020-09-05'
pick_up_time = "04:28:00" AND pick_up_date='2020-09-06'
注意:pick_up_date
、drop_off_date
数据库数据类型为:date
和 pick_up_time
、drop_off_time
数据库数据类型为 time
。
当pick_up_date
和drop_off_date
不相同时如何进行查询也有时隙检查?
$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;
}
原始 sql : select * from
保留where
vehicle_id = yourVehicleId and ( (
start_timestampbetween YourStartingDateTime and yourEndingDateTime or
end_timestamp between YourStartingDateTime and yourEndingDateTime ) or (
start_timestamp<= yourEndingDateTime and
end_timestamp >= YourStartingDateTime) )
我正在尝试使用 Laravel 5.8 构建租车预订流程。
我想显示所有可用的汽车,而在特定的 Reservation
table 之间找不到汽车
pick_up_date
和 drop_off_date
随着时间的推移。
我现在有什么?
我有pick_up_date
、pick_up_time
还有drop_off_date
、drop_off_time
还有vehicle_id
.
当我的 pick_up_date
和 drop_off_date
相同时,我能够弄清楚哪些车可用和不可用。
但我的问题是 drop_off_date
。
让我详细解释一下:
猜猜我正在尝试预订和我的
pick_up_time = "23:45:00" AND pick_up_date='2020-09-05'
pick_up_time = "04:28:00" AND pick_up_date='2020-09-06'
注意:pick_up_date
、drop_off_date
数据库数据类型为:date
和 pick_up_time
、drop_off_time
数据库数据类型为 time
。
当pick_up_date
和drop_off_date
不相同时如何进行查询也有时隙检查?
$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;
}
原始 sql : select * from
保留where
vehicle_id = yourVehicleId and ( (
start_timestampbetween YourStartingDateTime and yourEndingDateTime or
end_timestamp between YourStartingDateTime and yourEndingDateTime ) or (
start_timestamp<= yourEndingDateTime and
end_timestamp >= YourStartingDateTime) )