Is it possible to save a query bulider and use it multiple times?
for example, I have a model 'Tour'.
I create a long query buider and paginate it:
$tour = Tour::where(...)->orWhere(...)->orderBy(...)->paginate(10);
For example, 97 models qualify for the above query. "Paginate" method outputs first 10 models qualifying for the query, but I also need to so some operations on all 97 models. I don't want to 'repeat myself' writing this long query 2 times.
So I want something like:
$query = Tour::where(...)->orWhere(...)->orderBy(...); $tour1 = $query->paginate(10); $tour2 = $query->get();
Is that a correct way to do in Laravel? (my version is 5.4).