From 64c8767e8119343722b9e33fbe498c37a6e8a696 Mon Sep 17 00:00:00 2001 From: Petri Asikainen Date: Tue, 29 Jun 2021 12:28:32 +0300 Subject: [PATCH] Support images and multipart requests --- app/Http/Controllers/Api/DepartmentsController.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/app/Http/Controllers/Api/DepartmentsController.php b/app/Http/Controllers/Api/DepartmentsController.php index 872da9183d..f7a709a1dc 100644 --- a/app/Http/Controllers/Api/DepartmentsController.php +++ b/app/Http/Controllers/Api/DepartmentsController.php @@ -9,6 +9,7 @@ use App\Http\Transformers\SelectlistTransformer; use App\Models\Department; use Auth; use Illuminate\Http\Request; +use app\http\Requests\ImageUploadRequest; use Illuminate\Support\Facades\Storage; class DepartmentsController extends Controller @@ -73,14 +74,16 @@ class DepartmentsController extends Controller * * @author [A. Gianotto] [] * @since [v4.0] - * @param \Illuminate\Http\Request $request + * @param \App\Http\Requests\ImageUploadRequest $request * @return \Illuminate\Http\Response */ - public function store(Request $request) + public function store(ImageUploadRequest $request) { $this->authorize('create', Department::class); $department = new Department; $department->fill($request->all()); + $department = $request->handleImages($department) + $department->user_id = Auth::user()->id; $department->manager_id = ($request->filled('manager_id') ? $request->input('manager_id') : null); @@ -112,15 +115,16 @@ class DepartmentsController extends Controller * * @author [A. Gianotto] [] * @since [v5.0] - * @param \Illuminate\Http\Request $request + * @param \App\Http\Requests\ImageUploadRequest $request * @param int $id * @return \Illuminate\Http\Response */ - public function update(Request $request, $id) + public function update(ImageUploadRequest $request, $id) { $this->authorize('update', Department::class); $department = Department::findOrFail($id); $department->fill($request->all()); + $department = $request->handleImages($department); if ($department->save()) { return response()->json(Helper::formatStandardApiResponse('success', $department, trans('admin/departments/message.update.success')));