lundi 30 décembre 2019

How to add new key value pair in response of groupBy in laravel?

I have a order table where it contains id,order_id,user_id,etc

I applied groupBy() over order Eloquent like below:

`$orders = DB::table('orders')->whereUserId($userId)->groupBy('order_id')->get();`

So, here I am getting response like:

Collection {#547 ▼
  #items: array:1 [▼
    "d0b942a572941b90f385" => Collection {#535 ▼
      #items: array:4 [▼
        0 => Order {#561 ▶}
        1 => Order {#562 ▶}
        2 => Order {#563 ▶}
        3 => Order {#564 ▶}
      ]
    }
  ]
}

Now I am applying foreach loop over here so that I can add new kew value pair to particular above 4 array but Its now adding this new key value pair. I done the code like below:

foreach($orders as $order){

   $order['ee']='test';
 }

I am not getting where I am getting it wrong, because I check it line by line in foreach loop then it add it properly but while I check outside of loop, its now showing me this new key value pair



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2F3YFmN
via IFTTT

Aucun commentaire:

Enregistrer un commentaire