vendredi 11 octobre 2019

How to adapt my method update() in laravel 5.6

I want to adapt this code

$date_seance = $request->get('date_seance'); 
$fk_student = $request->get('fk_student');

$thisStudentsTrainings = Training::where('fk_student', $fk_student)->get();

$thisStudentsPayments = Payment::where('fk_student', $request->get('fk_student'))->get();

if(count($thisStudentsTrainings) >= count($thisStudentsPayments) * 5) {
    return redirect()->route('trainings.index') 
     ->with('error', 'You have reached your ceiling!'); 
 }

In my function update() I have this for now... I don't know how Can I adapt in my method correctly ??

public function update(Request $request, $id)
 {  


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

I have tried this:

public function update(Request $request, $id)
{  


   $date_seance = $request->get('date_seance'); 
   $fk_student = $request->get('fk_student');

   $thisStudentsTrainings = Training::where('fk_student', $fk_student)->get();
   $thisStudentsPayments = Payment::where('fk_student', $request->get('fk_student'))->get();

   if(count($thisStudentsTrainings) >= count($thisStudentsPayments) * 5) {
        return redirect()->route('trainings.index') 
        ->with('error', 'You have reached your ceiling!'); 
   }


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

   }

}

When, I want to change the value of the date_seance, I have the message You have reached your ceiling!.

I thank you in advance for your help.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire