/** * Implement getAdditional($id) */ public function getAdditional($id) { // using the Eloquent model return InboundOrderAdditional::whereObjectid($id)->limit(20)->get(); }
/** * Implement update($id, $input) */ public function update($id, $input) { $po = InboundOrder::find($id); $updatedPo = $po->update($input); //TODO find a way to automate which $name's are Additional, should not be hardcoded here. //TODO Found it!, if we subtract original attribute names from attributes, we get this list of Additional names $name = 'RouteNumber'; if (isset($input[$name])) { $additional = InboundOrderAdditional::where('objectID', $id)->where('Name', $name)->first(); if (isset($additional)) { $additional->update(['Value' => $input[$name]]); } else { InboundOrderAdditional::create(['objectID' => $id, 'Name' => $name, 'Value' => $input[$name]]); } } return $updatedPo; }