5 months ago

condition on a foreign key

Posted 5 months ago by david2000

I have to make 2 conditions:

  1. My first condition: I have to test that if I don't have a payment, I don't can encode a training.

  2. 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)
               '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();

            return redirect()->route('trainings.index')
                    ->with('error', 'No Payment, no training for you!');
            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 sign in or create an account to participate in this conversation.