0
我正在使用Laravel 5.3并进行查询,但需要在返回之前修改集合的数据结构。我试图通过将它们设置为一个空数组来清除这些命令,但它不清除(我仍然在返回的json中获得所有原始结果)。但是,如果我取消了它的工作顺序。事实上,无论我设置$ res-> product->命令,它都不起作用,除非我先将其解除。laravel清除并收集数据中的项目
$stores = array();
foreach($data as $key => $res) {
// This is a hacky way to clear the orders but it works
$orders = array();
unset($res->product->orders);
$res->product->orders = $orders;
// This is the way I would have done it but it doesn't work
$res->product->orders = array();
$stores[$res->store_id]['name'] = $res->product->store_name;
$stores[$res->store_id]['data'][] = $res;
}
你能告诉我们包含在$数据中的数据 –
不幸的是,数据是保密的,但它看起来像一个普通的集合对象,我得到的产品 – Jongo