mistre83's avatar

Sub query whereIn from existing query

Hi to all, for my application i have to do a sub-query (whereIn) from a previous query.

For example, in my code i have the query (this is just an example):

$query = Orders::where('status', '!=', 20);

Now that i have this query, i should use this to create another query, with whereIn clause:

$total = OrderTotals::whereIn('order_id', function($q) use($query) {
   // here i should use the result query created before
})->sum('value);

How i can use the $query inside the whereIn ?

0 likes
0 replies

Please or to participate in this conversation.