public function set_categories($params) { $categories = $this->orEq($params, 'payload', array()); foreach ($categories as &$category) { if (isset($category['id'])) { $actual = API\Category::find($category['id']); if ($actual->isValid()) { $actual->fromApiArray($category); $actual->update(); } else { $this->result->addError(__("Could not find that category"), JSONAPI_MODEL_NOT_EXISTS, array('id' => $category['id'])); return $this->done(); } } else { $actual = new API\Category(); $actual->create($category); $category = $category->asApiArray(); } $category = $actual->asApiArray(); } $this->result->setPayload($categories); return $this->done(); }