Level 75
You need to set it up so:
1 payment = 2 training sessions
// or
1 "block" of training
// so
blocks are increments of 2
2
4
6
8
Just fix the query logic.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
When I add a payment for a student in my form payment

the student can have 2 trainings (so, 1 payment = 2 trainings)
When, I want to add a second training in my form training, it blocks

In my Controller Training I have this:
public function store(Request $request)
{
$request->validate([
'date_seance' => 'required',
'hour_start' => 'required',
'hour_end' => 'required',
'fk_motorbike' => 'required',
'fk_former' => 'required',
'fk_student' => 'required',
'fk_typeseance' => 'required'
]);
$date_seance = $request->get('date_seance');
$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');
$payments = Payment::where('fk_student', $request->get('fk_student'))->first();
if(!isset($payments)){
return redirect()->route('trainings.index')
->with('error', 'No payment, no training! ');
}
$thisStudentsTrainings = Training::where('fk_student', $fk_student)->get();
if(count($thisStudentsTrainings) >= 2){
return redirect()->route('trainings.index')
->with('error', 'The ceiling is 2 trainings! ');
}
$thisStudentsPayments = Payment::where('fk_student', $request->get('fk_student'))->get();
if( count($thisStudentsPayments) < (count($thisStudentsTrainings) * 2) ) {
return redirect()->route('trainings.index')
->with('error', 'test!');
}
else{
Training::create($request->all());
return redirect()->route('trainings.index')
->with('success', 'Add');
}
}
I think the problem is here ?
if( count($thisStudentsPayments) < (count($thisStudentsTrainings) * 2) ) {
return redirect()->route('trainings.index')
->with('error', 'test!');
}
Thank you for your help.
One payment equals one block of training.
One block equals two training lessons.
Look at it in blocks of training.
Sorry if I cannot explain it better.
Please or to participate in this conversation.