I have a loop that runs a query and builds an associative array, one key/value pair for each result set. What's happening is that the scopes keep piling up as the loop iterates.
<?php
foreach ($master_asset_categories as $master_category) {
$master_assets_this_category = $asset_query->group($master_category->id)->get();
$master_asset_array[$master_category->id] =
$master_assets_this_category;
}
The group() scope keeps adding onto each loop so it results in something like...
group($master_category->id)->group($master_category->id)->group($master_category->id)->group($master_category->id)
With the $master_category->id being different with each loop. That makes the query return nothing since each Asset model has only one asset_group_id and all of the where clauses get chained with "and".
What can I use to remove the latest group() scope after each iteration so there is only the single current group ($master_category->id) scope used on each iteration?