From 53bd5626c9e3fda94f0394993d8384941d9a7f20 Mon Sep 17 00:00:00 2001 From: spencerrlongg Date: Wed, 1 Nov 2023 11:33:29 -0500 Subject: [PATCH] this works, need to write up pr --- app/Exceptions/Handler.php | 6 ++++++ app/Http/Requests/StoreAssetRequest.php | 8 +++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index 3d4db93452..b3317ad2df 100644 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -4,6 +4,7 @@ namespace App\Exceptions; use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler; use App\Helpers\Helper; +use Illuminate\Http\JsonResponse; use Illuminate\Validation\ValidationException; use Illuminate\Auth\AuthenticationException; use ArieTimmerman\Laravel\SCIMServer\Exceptions\SCIMException; @@ -150,6 +151,11 @@ class Handler extends ExceptionHandler return redirect()->guest('login'); } + protected function invalidJson($request, ValidationException $exception) + { + return response()->json(Helper::formatStandardApiResponse('error', null, $exception->errors()), 200); + } + /** * A list of the inputs that are never flashed for validation exceptions. diff --git a/app/Http/Requests/StoreAssetRequest.php b/app/Http/Requests/StoreAssetRequest.php index 992d67e25b..a9a06baed4 100644 --- a/app/Http/Requests/StoreAssetRequest.php +++ b/app/Http/Requests/StoreAssetRequest.php @@ -15,8 +15,8 @@ class StoreAssetRequest extends ImageUploadRequest */ public function authorize(): bool { - //TODO: make sure this works - //return Gate::allows('create', new Asset); + // TODO: make sure this works + return Gate::allows('create', new Asset); } public function prepareForValidation(): void @@ -36,13 +36,11 @@ class StoreAssetRequest extends ImageUploadRequest parent::rules(), ); - if(!$this->expectsJson()) { - //accepts an array for the gui form + // unsets unique check here, that check cannot run twice. $rules['asset_tags.*'] = $rules['asset_tag']; unset($rules['asset_tag']); $rules['serials.*'] = $rules['serial']; unset($rules['serial']); - } return $rules; }