In my form Payments
, I have 4 fields (date_payment, type_sitting, number_seance, fk_student)
Then, in my form trainings
I have 3 fields (date_sitting, fk_payment, fk_student)
.
I want to do a checking in my form trainings
and block with an error message if the number of seance is unlimited.
Here is an idea of my Training Controller
public function store(Request $request)
{
$request->validate([
'date_sitting' => 'required',
'fk_payment' => 'required',
'fk_student' => 'required'
]);
$exists = Training::where('date_sitting', $request->get('date_sitting'))->where('fk_payment', $request->get('fk_payment'))->where('fk_student', $request->get('fk_student'))->count();
if (!$exists){
$payment = Payment::where('fk_student', $request->get('fk_student'))->first();
if(!isset($payment)){
return redirect()->route('trainings.index')
->with('error', 'No Payment, no training for you!');
}
else{
Training::create($request->all());
return redirect()->route('trainings.index')
->with('success', 'new data created successfully');
}
}
}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire