Returning JSON depending on the route_id
How about somethink like:

 $allOrders = array();
 foreach($allWayPoints as $allWayPoint)
 {
            $allOrdersInWaypoint = Transaction::where('waypoint_id', "=", $allWayPoint)-&gt;where('type', "=", "DD")-&gt;get()-&gt;lists('order_id');
 //           $allOrders[] = array($allOrdersInWaypoint);
            $allOrders = array_merge($allOrders, $allOrdersInWaypoint);
 }

 foreach($allOrders as $order)
 {
       $otherOrders = Order::find($order);

       if(isset($otherOrders))
       {
            $getOtherOrders[] = array(
                                            'id'             =&gt; $otherOrders-&gt;id,
                                            'tracking_id'    =&gt; $otherOrders-&gt;tracking_id,
                                            'shipper_ref_no' =&gt; $otherOrders-&gt;shipper_ref_no);
       }
 }


Then they wont be nested and $allOrders will simply be a flat array containing the numbers, assuming $allOrdersInWaypoint is a array of numbers.