mercredi 24 novembre 2021

Laravel eloquent call realtionship based on a boolean parameter

I'm trying to make a method to retrieve model with a relationship I'd like to be able to fetch the relation based on a boolean parameter for example, I can do it using the if condition like the following

if($load == true){
   $users = User::with('login')->all()->paginate();
}else{
$users = User::all()->paginate();
}

I'm wondering if there's a way to do it without the if condition on the fly



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire