json响应值中的问题不能正确表达

时间:2016-07-25 09:04:19

标签: json laravel-5

$order_info = DB::table('order_assignments')
                                ->join('order', 'order_assignments.order_id', '=', 'order.id')
                                ->join('order_status', 'order.order_status_id', '=', 'order_status.order_status_id')
                                ->join('users', 'order.customer_id', '=', 'users.id')
                                ->join('address', 'order.address_id', '=', 'address.id')
                                ->where('delivery_boy_id', $delivery_boy_id)
                                ->where('is_accept', 1)
                                ->whereRaw('order_assignments.delivery_completed_at < order_assignments.time_of_assignment')
                                ->get();
                       //dd($order_info); 



                 if ($order_info) {
                    foreach ($order_info as $value1) {
                    $value = $value1;
                     $orderModel = new Order();
                     $order_info = $orderModel->getOrderDetailsForId($value->order_id);
                    $this->response['bill']= ['item' =>$order_info['orderDishes'],'service_charge' => $value->total_sercharge, 'total_amount' => $value->total_amount, 'comment' => 'completed on time', 'customer'=>['address' => $value->address, 'Name' => $value->name], 'distance_traveled' =>'7 k.m', 'picker' => 1, 'restaurant' =>['address' => 'c-3', 'lat' => '77.2222', 'long' => '77025698'], 'time_taken'=> '2hours', 'status' => 'completed', 'uid' => $value->order_id ];
                }
                    // $this->response['customer'] = ['address' => $value->address ];
                    return json_encode($this->response);  
                    } 

                 }

当我运行这个代码时,它只能在jason中的数据库中显示最后的订单ID,而表中有两个订单ID。请任何人帮我解决这个问题

1 个答案:

答案 0 :(得分:0)

$this->response['bill'] = .... //

修改此行,如下所示:

$this->response['bill'][]= ['item' =>$order_info['orderDishes'],'service_charge' => $value->total_sercharge, 'total_amount' => $value->total_amount, 'comment' => 'completed on time', 'customer'=>['address' => $value->address, 'Name' => $value->name], 'distance_traveled' =>'7 k.m', 'picker' => 1, 'restaurant' =>['address' => 'c-3', 'lat' => '77.2222', 'long' => '77025698'], 'time_taken'=> '2hours', 'status' => 'completed', 'uid' => $value->order_id ];