API call to update existing components

This commit is contained in:
manavo
2014-11-25 21:43:36 +00:00
parent f71639f226
commit c3febdb490
3 changed files with 38 additions and 11 deletions

View File

@@ -44,18 +44,24 @@
public function postComponents() {
$component = new Component(Input::all());
$component->user_id = $this->auth->user()->id;
if ($component->isValid()) {
try {
$component->saveOrFail();
return $component;
} catch (Exception $e) {
App::abort(500, $e->getMessage());
}
} else {
App::abort(404, $component->getErrors()->first());
}
return $this->_saveComponent($component);
}
/**
* Update an existing component
*
* @param int $id
*
* @return Component
*/
public function putComponent($id) {
$component = $this->getComponent($id);
$component->fill(Input::all());
return $this->_saveComponent($component);
}
/**
* Get all incidents
*
@@ -130,6 +136,26 @@
}
}
/**
* Function for saving the component, and returning appropriate error codes
*
* @param Component $component
*
* @return Component
*/
private function _saveComponent($component) {
if ($component->isValid()) {
try {
$component->saveOrFail();
return $component;
} catch (Exception $e) {
App::abort(500, $e->getMessage());
}
} else {
App::abort(404, $component->getErrors()->first());
}
}
/**
* Function for saving the incident, and returning appropriate error codes
*