Home > Back-end >  (SOLVED) I'm working at laravel project but there is always that error : ErrorException Creatin
(SOLVED) I'm working at laravel project but there is always that error : ErrorException Creatin

Time:04-20

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();

CodePudding user response:

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();

}


  • Related