Sep 9, 2019
0
Level 1
condition on a foreign key
I have to make 2 conditions:
-
My first condition: I have to test that if I don't have a payment, I don't can encode a training.
-
Then, my second condition (very difficult for me), the number of seance must be equal to the number of reservation. For example: 1 seance = 1 training. For now, my bookings are unlimited... :-(
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');
}
}
}
My tables are:
Training = date_sitting, fk_payment, fk_student
Payment = date_payment, number_seance , price, total, fk_student
Please or to participate in this conversation.