First, the $request->validate() method returns an array so this
$request->validate([
'date_seance' => 'required',
'hour_start' => 'required',
'hour_end' => 'required',
'fk_student' => 'required'
]);
$date_seance = $request->get('date_seance');
$hour_start = $request->get('hour_start');
$hour_end = $request->get('hour_end');
$fk_student = $request->get('fk_student');
should look like this
$form = $request->validate([
'date_seance' => 'required',
'hour_start' => 'required',
'hour_end' => 'required',
'fk_student' => 'required'
]);
$date_seance = $form['date_seance'];
$hour_start = $form['hour_start'];
// and so on ...
2nd thing is you shouldn't use ->get() if you need only to count stuff. So this
$thisStudentsTrainings = Training::where('fk_student', $fk_student)->get();
$thisStudentsPayments = Payment::where('fk_student', $request->get('fk_student'))->get();
should be like this
$thisStudentsTrainings = Training::where('fk_student', $form['fk_student'])->count();
$thisStudentsPayments = Payment::where('fk_student', $form['fk_student'])->count();
if($thisStudentsTrainings >= $thisStudentsPayments * 5) {
return redirect()->route('trainings.index')
->with('error', 'ceiling reached!');
}
As for your update() method, it should be pretty much the sames as in the store() method, because i guess he's only allowed only to change the date and time when the training will happen... so that means he won't add a new training and if updating it doesn't affect the payment you shouldn't check for that again.