Reputation: 167
I am doing a reservation system ... and I am having the following problems:
People can book for example from 11/06/2020 - 10:00 to 11:00 am ... registered this ... the second client cannot register for example from 11/06/2020 - 10:30 to 11:30 (since it is busy) so far everything is perfect ...
Problem 1) But if the reservation is from 11/06/2020 - 10:00 a.m. to 11:00 a.m. ... does not allow a client to register from 11/06/2020 - 11:00 a.m. to 12:00 p.m. ... they must do so from 11/06/2020 - 11:01 a.m. to 12:00 p.m. ...
Problem 2) if a customer registers 11/06/2020 - 11:00 to 12:00
it lets me register 11/06/2020 - 1:00 p.m. to 3:00 p.m. for example but not ...
11/07/2020 - 11:00 to 12:00
He says the schedule is already busy, but he's not comparing the day to me ...
public function validarFecha($fecha, $horaInicial, $horaFinal)
{
$agenda = Booking::select("*")
->whereDate('day', $fecha)
->whereBetween('hour_start', [$horaInicial, $horaFinal])
->orWhereBetween('hour_end', [$horaInicial, $horaFinal])
->first();
return $agenda == null ? true : false;
}
-----------------------------
public function store(Request $request)
{
$input = $request->all();
if($this->validarFecha($input["txtFechaInicio"], $input["txtHoraInicio"], $input["txtHoraFinal"])){
$agenda = Booking::create([
"id_user"=>$input["ddlUsuarios"],
"day"=>$input["txtFechaInicio"],
"hour_start"=>$input["txtHoraInicio"],
"hour_end"=>$input["txtHoraFinal"],
"observation"=>$input["txtDescripcion"]
]);
return response()->json(["ok"=>true]);
}else{
return response()->json(["ok"=>false]);
}
dd($input);
}
Upvotes: 0
Views: 123
Reputation: 50767
Just add an additional comparison in your ternary to determine if $horaInicial
matches $agenda->hour_end
where you return false, something like:
return $agenda === null || $agenda->hour_end === $horaInicial
As long as no agenda exists, or the end of the agenda matches the beginning of the agenda, then we will have a valid
start time.
Upvotes: 1