For each payment, the student can follow a training.
For example, I encode a payment for the student Menier
.
Then, I encode un training for the student Menier
.
It's correct !
Now, when I encode another payment for the same student Menier
I can't add a training, it's blocking ???
How to put to zero the checking, after each payment of the student?
$conflitpayment = Payment::where('fk_student', $request->get('fk_student'))
->whereDate('date_payment', ">" , $date_seance)
->first();
if(isset($conflitpayment)){
return redirect()->route('trainings.index')
->with('error', 'Payment! ');
}
$thisStudentsTrainings = Training::with(['payments' => function($query) use($fk_student){
$query->where('fk_student', $fk_student);
}])->get();
$hasPaidForThisTraining = $thisStudentsTrainings ->contains('id', $request->get('fk_training'));
if( count($thisStudentsTrainings) >= 1) {
return redirect()->route('trainings.index')
->with('error', 'No payment ! ');
}
else{
Training::create($request->all());
return redirect()->route('trainings.index')
->with('success', 'Add');
}
Thank you for your help.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire