/** * Update the specified resource in storage. * * @param int $id * @return Response */ public function update($id) { if (Auth::hasPermission('update')) { try { $attributes = $this->filterAndValidate(); $updated = $this->sections->update($id, $attributes['title'], $attributes['alias'], $attributes['icon'], $attributes['is_fertile'], $attributes['is_roleable']); if (Input::has('parent') && Input::get('parent') > 0) { // Only when we receive a Section's Id we proceed with setting it as a parent // bcz sometimes when updating other section info we'll get the parent title instead. if (is_numeric($attributes['parent'])) { $updated->parent()->associate($this->sections->find($attributes['parent']))->save(); } } return Response::json($updated); throw new UnauthorizedException(); } catch (\Illuminate\Database\Eloquent\ModelNotFoundException $e) { return Response::json(['error' => Lang::get('errors.section_not_found')], 404); } catch (\Exception $e) { return Response::json(['error' => Lang::get('errors.unexpected')], 500); } } }