you can remove the with conditions to scopes and then use those scopes to build more complex queries
Oct 25, 2023
3
Level 1
Eloquent ORM Eager Loading dynamic ?
Hello, i have 1 function reuse in model, but for many reason, this need with diffenrent. How i can control this ?
In below, you can see i use 4 with, but i not need 4 with in all case, some with1, with2 or only with1.
If pass with by params to function, it make function complex, not clearly. if clone to many function, it not a good solution.
return $this->with('with1')->with('with2')->with('with3')->with('with4')->where(...)->where(...)->get();
Please or to participate in this conversation.