/** * Implement getAdditional($id) */ public function getAdditional($id) { // using the Eloquent model return InboundOrderDetailAdditional::whereObjectid($id)->limit(20)->get(); }
/** * Implement update($id, $input) */ public function update($id, $input) { $pod = InboundOrderDetail::find($id); $updatedPod = $pod->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 = 'Location'; //$newValue = $input[$name]; if (isset($input[$name])) { $additional = InboundOrderDetailAdditional::where('objectID', $id)->where('Name', $name)->first(); if (isset($additional)) { $additional->update(['Value' => $input[$name]]); $additional->save(); //dd(compact('id','input','newValue','additional')); // Update does not appear to be working, deleting the record instead InboundOrderDetailAdditional::where('objectID', $id)->where('Name', $name)->delete(); } if ($input[$name] > 0) { InboundOrderDetailAdditional::create(['objectID' => $id, 'Name' => $name, 'Value' => $input[$name]]); } } return $updatedPod; }