0
私はLaravel 5.3を使用していますが、クエリを持っていますが、コレクションのデータ構造を変更する必要があります。空の配列に設定して注文をクリアしようとしていますが、クリアされません(返されたjsonの元の結果はすべて取得しています)。しかし、私が注文を解除すると、それは動作します。実際、私が$ res-> product-> ordersを何に設定しても、最初にそれを設定しない限り、うまくいきません。laravel clearとcollection dataの項目
$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;
}
はあなたが私たちに$データに含まれるデータを表示することができ、任意のlaravel 5.3は、両方のクエリbuliderにcollectionを返します変換コレクションを試すことができます –
残念ながらデータは機密ですが、それは次のようになります正規のコレクションオブジェクトと私は製品を得る – Jongo