在预订时段时,我想检查该插槽是否与任何其他已预订的时段重叠。使用以下查询不正确的相同:
Availability::where('date',date('Y-m-d',strtotime($request->available_date)))
->where(function ($query) use($request){
$query->whereBetween('start_time', [date("H:i:s", strtotime($request->start_time)), date("H:i:s", strtotime($request->end_time))])
->orWhereBetween('end_time', [date("H:i:s", strtotime($request->start_time)), date("H:i:s", strtotime($request->end_time))]);
})
->get();
提前致谢!
答案 0 :(得分:2)
首先,为了能够在查询结束中访问$endTime
和use
,您需要使用function ($query) use ($startTime, $endTime)
结构传递它们,即
$startTime = $request->start_time;
$endTime = $request->end_time;
$Availability = Availability::where(function ($query) use ($startTime, $endTime) {
$query
->where(function ($query) use ($startTime, $endTime) {
$query
->where('start_time', '<=', $startTime)
->where('end_time', '>', $startTime);
})
->orWhere(function ($query) use ($startTime, $endTime) {
$query
->where('start_time', '<', $endTime)
->where('end_time', '>=', $endTime);
});
})->count();
尝试如下:
private subject: Subject<any> = new Subject<any>();
public observer: Observable<any>;
constructor() {
this.observer = this.subject.debounceTime(300).switchMap(// do something);
}
希望这会对你有帮助!
答案 1 :(得分:0)
少量修改查询,希望它对所有搜索时隙预订算法的人都适用。
$Availability= Availability::
where(function ($query) use ($start_time, $end_time) {
$query
->whereBetween('start_time', [$start_time, $end_time])
->orWhere(function ($query) use ($start_time, $end_time) {
$query
->whereBetween('end_time', [$start_time, $end_time]);
});
})->count();