Mathieu Mourareau
Mathieu Mourareau

Reputation: 1220

Condition in controller select the next id

I try to select an ID in my controller and add +1 to select the next one but it's return my a null object . someone have an idea how to select +1 id ? thanks a lot in advance

here my controller

//condition if checkbox is selected !

        if($licencie_amateur->surclasser === true ){


            $licencie_amateur->lb_surclassement =  ActiviteLicencie::where('catg_licence_id' ,  '=' , $categorie_age->id+1 )->first();

        }elseif ($licencie_amateur->surclasser === false){

            // do nothing 

        }

Upvotes: 1

Views: 73

Answers (1)

Alexey Mezenin
Alexey Mezenin

Reputation: 163898

Your solution will not work since result can be empty. So, do this instead:

ActiviteLicencie::where('catg_licence_id',  '>', $categorie_age->id)
    ->orderBy('catg_licence_id')
    ->first();

Upvotes: 1

Related Questions