this is my candidatController.php
the error is in the line before the last line($prev_canditure->etat="archifé";
)
$candidat_nw=Candidat::orderby('created_at','DESC')->first(); $prev_canditure=Candidature::where('candidat_id','=',$candidat->id)->orderby('created_at', 'DESC')->first(); $prev_canditure->etat = "Archivé"; $prev_canditure->save();
Advertisement
Answer
From your code you can use a defensive code approach by checking if the query will return null
$candidat_nw=Candidat::orderby('created_at','DESC')->first(); $prev_canditure=Candidature::where('candidat_id','=',$candidat->id)->orderby('created_at', 'DESC')->first(); if (!(empty($prev_candidature))){ $prev_canditure->etat = "Archivé"; $prev_canditure->save(); }