Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

david2000's avatar

eloquant date & hours

I am stuck about a problem concerning the hours en laravel.

In my form Training, I have several recordings.

For example, I want to add an other recording

On 20/09/2019 From 08:00 to 10:00

When, I confirm, I have a duplicate system...

The problem is that I don't have a recording for on 20/09/2019 From 08:00 to 10:00

In fact, my code blocks the hours even if the dates are different, how can I solve this problem?

 $date_seance = Carbon::parse($request->get('date_seance'))->format('Y-m-d');
 $hour_start = $request->get('hour_start'); 
 $hour_end = $request->get('hour_end'); 

 $fk_motorbike = $request->get('fk_motorbike');
 $fk_student = $request->get('fk_student');
 $fk_former = $request->get('fk_former');
 $fk_typeseance = $request->get('fk_typeseance');

       
 $conflictTraining1 = Training::where('fk_motorbike', $request->get('fk_motorbike')) 
 ->whereDate('date_seance', "=" , Carbon::parse($date_seance)) 
 ->where('hour_start', "<=" , $request->get('hour_start')) 
 ->where('hour_end', ">=" , $request->get('hour_end'))
 ->where('fk_former', $request->get('fk_former'))
 ->first();

 $conflictTraining2 = Training::where('fk_motorbike', $request->get('fk_motorbike')) 
 ->where('hour_start', "<=" , $request->get('hour_start')) 
 ->where('hour_end', ">=" , $request->get('hour_end'))
 ->where('fk_former', $request->get('fk_former'))
 ->first();
0 likes
3 replies
douglasakula's avatar

.... and there is no unique constraints on your database tables. Right ?

Sinnbeck's avatar

Can you show the logic for actually checking if there is a booking? This just gets them from the database.

Please or to participate in this conversation.