【发布时间】:2016-11-16 04:44:16
【问题描述】:
我正在使用 Laravel 5.3 并且有一个查询,但需要在返回之前修改集合的数据结构。我试图通过将订单设置为空数组来清除订单,但它并不清楚(我仍然在返回的 json 中获得所有原始结果)。但是,如果我取消设置它的订单。事实上,无论我设置什么 $res->product->orders 都不起作用,除非我先取消设置。
$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;
}
【问题讨论】:
-
你能告诉我们$data中包含的数据吗
-
不幸的是,数据是机密的,但它看起来像一个普通的集合对象,我得到了产品
标签: laravel