u can use
get() instead of all()
and here is union method
Is there an equivalent of the all() scope that returns an instance of Eloquent Builder instead of Collection. I need to chain some queries together and end with pagination, like this:
$users = User::where('id','!=', 0); // not very beautiful
if($filterA){
$users = $users->whereHas('thing');
}
if($filterB){
$users = $users->where('other_thing', 'some_value');
}
$users->paginate(5);
I used a hacky solution to return an instance of Eloquent Builder that contains all the models. If I went with $users->User::all() the whereHas() and paginate() would fail.
Is there a more Laravel to achieve what I'm doing?
Please or to participate in this conversation.