From a7b1e31776e24454a709dfd906ab11e2e0c4ce30 Mon Sep 17 00:00:00 2001 From: Petri Asikainen Date: Tue, 29 Jun 2021 12:27:08 +0300 Subject: [PATCH] Support images and multipart requests --- app/Http/Controllers/Api/ComponentsController.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/app/Http/Controllers/Api/ComponentsController.php b/app/Http/Controllers/Api/ComponentsController.php index d7af18b21c..d7654a920d 100644 --- a/app/Http/Controllers/Api/ComponentsController.php +++ b/app/Http/Controllers/Api/ComponentsController.php @@ -8,6 +8,7 @@ use App\Http\Transformers\ComponentsTransformer; use App\Models\Company; use App\Models\Component; use Illuminate\Http\Request; +use App\Http\Requests\ImageUploadRequest; class ComponentsController extends Controller { @@ -78,14 +79,15 @@ class ComponentsController 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', Component::class); $component = new Component; $component->fill($request->all()); + $component = $request->handleImages($component); if ($component->save()) { return response()->json(Helper::formatStandardApiResponse('success', $component, trans('admin/components/message.create.success'))); @@ -116,15 +118,17 @@ class ComponentsController extends Controller * * @author [A. Gianotto] [] * @since [v4.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', Component::class); $component = Component::findOrFail($id); $component->fill($request->all()); + $component = $request->handleImages($component); + if ($component->save()) { return response()->json(Helper::formatStandardApiResponse('success', $component, trans('admin/components/message.update.success')));