From b67b00dd82af6c32636d645d88990b5d5d19b9ab Mon Sep 17 00:00:00 2001 From: spencerrlongg Date: Tue, 31 Oct 2023 21:06:44 -0500 Subject: [PATCH] this is a start, something up with asset_tag unique rule --- app/Http/Controllers/Api/AssetsController.php | 4 +- app/Http/Requests/StoreAssetRequest.php | 49 +++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 app/Http/Requests/StoreAssetRequest.php diff --git a/app/Http/Controllers/Api/AssetsController.php b/app/Http/Controllers/Api/AssetsController.php index bbdc982599..c32c3c4429 100644 --- a/app/Http/Controllers/Api/AssetsController.php +++ b/app/Http/Controllers/Api/AssetsController.php @@ -3,6 +3,7 @@ namespace App\Http\Controllers\Api; use App\Events\CheckoutableCheckedIn; +use App\Http\Requests\StoreAssetRequest; use Illuminate\Support\Facades\Gate; use App\Helpers\Helper; use App\Http\Controllers\Controller; @@ -33,6 +34,7 @@ use TCPDF; use Validator; use Route; + /** * This class controls all actions related to assets for * the Snipe-IT Asset Management application. @@ -532,7 +534,7 @@ class AssetsController extends Controller * @since [v4.0] * @return \Illuminate\Http\JsonResponse */ - public function store(ImageUploadRequest $request) + public function store(StoreAssetRequest $request) { $this->authorize('create', Asset::class); diff --git a/app/Http/Requests/StoreAssetRequest.php b/app/Http/Requests/StoreAssetRequest.php new file mode 100644 index 0000000000..992d67e25b --- /dev/null +++ b/app/Http/Requests/StoreAssetRequest.php @@ -0,0 +1,49 @@ +getRules(), + parent::rules(), + ); + + if(!$this->expectsJson()) { + //accepts an array for the gui form + $rules['asset_tags.*'] = $rules['asset_tag']; + unset($rules['asset_tag']); + $rules['serials.*'] = $rules['serial']; + unset($rules['serial']); + } + + return $rules; + } +}