public function editOrder($id) { $dbs = new MemberDBS(); $post = Input::get(); $rd = DB::collection($dbs->getTable())->get(); Eloquent::unguard(); for ($i = 0; $i < count($rd); $i++) { $mem = $rd[$i]; if (array_key_exists('Order', $mem)) { $data = $mem['Order']; $found = false; $payload = array(); $ori = ''; $new = ''; $data1 = array(); for ($j = 0; $j < count($data); $j++) { $item = $data[$j]; if ($item['Order_id'] == $id) { $found = true; $save = $item['product']; /* $data1 = array('Order_id'=>$item['Order_id']); $data1 = $data1 + $post;*/ $ori = $item['product']; $data1 = array_merge($item, $post); $new = $data1['product']; array_push($payload, $data1); } else { array_push($payload, $item); } } if ($found) { $doc = $dbs->where('_id', $mem['_id']); if ($doc->update(array('Order' => $payload))) { $ProductController = new ProductController(); if ($ProductController->deleteOrderOfProduct($ori, $id)) { if ($ProductController->addOrderOfProduct($new, $data1['Order_id'])) { return Response::json(array('message' => 'success')); } } else { return Response::json(array('message' => 'error')); } } else { return Response::json(array('message' => 'error')); } } } } return Response::json(array('message' => 'Order not found')); }