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



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/3cPZT5O
via IFTTT

Aucun commentaire:

Enregistrer un commentaire