Support images and multipart requests

This commit is contained in:
Petri Asikainen 2021-06-29 12:27:08 +03:00
parent 604a0b6df1
commit a7b1e31776

View file

@ -8,6 +8,7 @@ use App\Http\Transformers\ComponentsTransformer;
use App\Models\Company; use App\Models\Company;
use App\Models\Component; use App\Models\Component;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use App\Http\Requests\ImageUploadRequest;
class ComponentsController extends Controller class ComponentsController extends Controller
{ {
@ -78,14 +79,15 @@ class ComponentsController extends Controller
* *
* @author [A. Gianotto] [<snipe@snipe.net>] * @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v4.0] * @since [v4.0]
* @param \Illuminate\Http\Request $request * @param \App\Http\Requests\ImageUploadRequest $request
* @return \Illuminate\Http\Response * @return \Illuminate\Http\Response
*/ */
public function store(Request $request) public function store(ImageUploadRequest $request)
{ {
$this->authorize('create', Component::class); $this->authorize('create', Component::class);
$component = new Component; $component = new Component;
$component->fill($request->all()); $component->fill($request->all());
$component = $request->handleImages($component);
if ($component->save()) { if ($component->save()) {
return response()->json(Helper::formatStandardApiResponse('success', $component, trans('admin/components/message.create.success'))); return response()->json(Helper::formatStandardApiResponse('success', $component, trans('admin/components/message.create.success')));
@ -116,15 +118,17 @@ class ComponentsController extends Controller
* *
* @author [A. Gianotto] [<snipe@snipe.net>] * @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v4.0] * @since [v4.0]
* @param \Illuminate\Http\Request $request * @param \App\Http\Requests\ImageUploadRequest $request
* @param int $id * @param int $id
* @return \Illuminate\Http\Response * @return \Illuminate\Http\Response
*/ */
public function update(Request $request, $id) public function update(ImageUploadRequest $request, $id)
{ {
$this->authorize('update', Component::class); $this->authorize('update', Component::class);
$component = Component::findOrFail($id); $component = Component::findOrFail($id);
$component->fill($request->all()); $component->fill($request->all());
$component = $request->handleImages($component);
if ($component->save()) { if ($component->save()) {
return response()->json(Helper::formatStandardApiResponse('success', $component, trans('admin/components/message.update.success'))); return response()->json(Helper::formatStandardApiResponse('success', $component, trans('admin/components/message.update.success')));