diff --git a/app/controllers/ApiController.php b/app/controllers/ApiController.php index cd1ea87e..1772858a 100644 --- a/app/controllers/ApiController.php +++ b/app/controllers/ApiController.php @@ -88,6 +88,32 @@ public function postIncidents() { $incident = new Incident(Input::all()); $incident->user_id = $this->auth->user()->id; + return $this->saveIncident($incident); + } + + /** + * Update an existing incident + * + * @param int $id + * + * @return Incident + */ + public function putIncident($id) { + $incident = $this->getIncident($id); + + $incident->fill(Input::all()); + + return $this->saveIncident($incident); + } + + /** + * Function for saving the incident, and returning appropriate error codes + * + * @param Incident $incident + * + * @return Incident + */ + private function saveIncident($incident) { if ($incident->isValid()) { try { $component = $incident->parent; @@ -104,4 +130,5 @@ App::abort(404, $incident->getErrors()->first()); } } + } diff --git a/app/models/Component.php b/app/models/Component.php index e1aa495d..9e2209d0 100644 --- a/app/models/Component.php +++ b/app/models/Component.php @@ -11,7 +11,7 @@ 'status' => 'required|integer' ]; - protected $fillable = ['user_id', 'name', 'description', 'status']; + protected $fillable = ['name', 'description', 'status']; /** * Lookup all of the incidents reported on the component. diff --git a/app/models/Incident.php b/app/models/Incident.php index 0f9ab1f3..1bcc8bea 100644 --- a/app/models/Incident.php +++ b/app/models/Incident.php @@ -14,7 +14,7 @@ 'message' => 'required', ]; - protected $fillable = ['user_id', 'component', 'name', 'status', 'message']; + protected $fillable = ['component', 'name', 'status', 'message']; /** * An incident belongs to a component. diff --git a/app/routes/api.php b/app/routes/api.php index 3522a5f0..13685a4c 100644 --- a/app/routes/api.php +++ b/app/routes/api.php @@ -11,6 +11,8 @@ Route::group(['protected' => true], function() { Route::post('components', 'ApiController@postComponents'); Route::post('incidents', 'ApiController@postIncidents'); + + Route::put('incidents/{id}', 'ApiController@putIncident'); }); });