From 0e0fe967e4706331ab5d7b7472da5335aa9990ff Mon Sep 17 00:00:00 2001 From: Godfrey Martinez <47435081+Godmartinz@users.noreply.github.com> Date: Mon, 10 Feb 2020 19:27:23 -0800 Subject: [PATCH] BadMethodCallException Method update does [ch10544] (#7804) --- .../Controllers/Api/DepartmentsController.php | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/Api/DepartmentsController.php b/app/Http/Controllers/Api/DepartmentsController.php index 2105346e63..91254af284 100644 --- a/app/Http/Controllers/Api/DepartmentsController.php +++ b/app/Http/Controllers/Api/DepartmentsController.php @@ -15,7 +15,7 @@ class DepartmentsController extends Controller /** * Display a listing of the resource. * - * @author [A. Gianotto] [] + * @author [Godfrey Martinez] [] * @since [v4.0] * @return \Illuminate\Http\Response */ @@ -163,5 +163,28 @@ class DepartmentsController extends Controller return (new SelectlistTransformer)->transformSelectlist($departments); } + /** + * Update the specified resource in storage. + * + * @author [Godfrey Martinez] [] + * @since [v4.0] + * @param \Illuminate\Http\Request $request + * @param int $id + * @return \Illuminate\Http\Response + */ + public function update(Request $request, $id) + { + $this->authorize('update', Department::class); + $departments = Department::findOrFail($id); + $departments->fill($request->all()); + + if ($departments->save()) { + return response() + ->json(Helper::formatStandardApiResponse('success', (new DepartmentsTransformer())->transformdepartment($departments), trans('admin/departments/message.update.success'))); + } + + return response() + ->json(Helper::formatStandardApiResponse('error', null, $departments->getErrors())); + } }