Laravel 8.x
I'm trying to do something like mentioned over here
(code copied from above link- minor change to comment)
$total = OrderTotals::whereIn('order_id', function($q) use($query) {
// here would like to use the query of the parent instead of an empty fresh query
})->sum('value);
Where I would like to use the previous query in the subquery when calling ->whereIn
is this possible how can I do this?
The $query
variable in the closure is empty and produces a select *
without any from or wheres. This make sense since a subquery can be wanted to be fresh. But what if I would like to use the existing query?
I used this google search among many others to find a similar question. The results on stackoverflow don't seem to use the existing query, they all add new from
s and where
s (see here and this highly rated question).