david2000
1 month ago
807
14
General

checking date payment for my function update()

Posted 1 month ago by david2000

I have to do a checking between the payment date and the seance date in my method store(). The method store() is OK!

$datePayment = Payment::where('fk_student', $request->get('fk_student'))
->whereDate('date_payment', ">" , $date_seance)
->first();

 if(isset($datePayment)){
            return redirect()->route('trainings.index')
                ->with('error', 'There is a problem with the payment date! ');
}

My problem is in my function update(), I am stuck. When, I change the value of the date_seance, there is no checking.

$datePayment = Payment::where('fk_student', $request->get('fk_student'))
->whereDate('date_payment', ">" , $date_seance)
->first();

if(isset($datePayment)){
    return redirect()->route('trainings.index')
    ->with('error', 'There is a problem with the payment date! ');
}

else{
   $trainings = Training::find($id);
   $trainings->date_seance = $request->get('date_seance');
   ...
   $trainings->save();
   return redirect()->route('trainings.index')
    ->with('success', 'Update!')->withInput();
   }

I know my problem is here in the condition:

if(isset($datePayment)){
        return redirect()->route('trainings.index')
        ->with('error', 'There is a problem with the payment date! ');
    }

Thank you for your help.

Please sign in or create an account to participate in this conversation.