From 604a0b6df150f94794e2159f8f27d008519cd530 Mon Sep 17 00:00:00 2001 From: Petri Asikainen Date: Tue, 29 Jun 2021 12:26:59 +0300 Subject: [PATCH] Support images and multipart requests --- app/Http/Controllers/Api/CompaniesController.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/app/Http/Controllers/Api/CompaniesController.php b/app/Http/Controllers/Api/CompaniesController.php index c56ed9f871..8b471f27b3 100644 --- a/app/Http/Controllers/Api/CompaniesController.php +++ b/app/Http/Controllers/Api/CompaniesController.php @@ -8,6 +8,7 @@ use App\Http\Transformers\CompaniesTransformer; use App\Http\Transformers\SelectlistTransformer; use App\Models\Company; use Illuminate\Http\Request; +use App\Http\Requests\ImageUploadRequest; use Illuminate\Support\Facades\Storage; class CompaniesController extends Controller @@ -65,15 +66,16 @@ class CompaniesController 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', Company::class); $company = new Company; $company->fill($request->all()); - + $company = $request->handleImages($company); + if ($company->save()) { return response()->json(Helper::formatStandardApiResponse('success', (new CompaniesTransformer)->transformCompany($company), trans('admin/companies/message.create.success'))); } @@ -104,15 +106,16 @@ class CompaniesController 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', Company::class); $company = Company::findOrFail($id); $company->fill($request->all()); + $company = $request->handleImages($company); if ($company->save()) { return response()