From f6ab0f8f463ecbc27f4e186fe16668a7811438e8 Mon Sep 17 00:00:00 2001 From: spencerrlongg Date: Wed, 13 Mar 2024 15:57:10 -0500 Subject: [PATCH] lots of cleanup to do, but this DOES work --- app/Http/Requests/UpdateAssetRequest.php | 28 ++++++++++++++++++++---- app/Models/Asset.php | 2 +- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/app/Http/Requests/UpdateAssetRequest.php b/app/Http/Requests/UpdateAssetRequest.php index afee0fb904..71792b85fc 100644 --- a/app/Http/Requests/UpdateAssetRequest.php +++ b/app/Http/Requests/UpdateAssetRequest.php @@ -4,6 +4,7 @@ namespace App\Http\Requests; use App\Models\Asset; use Illuminate\Support\Facades\Gate; +use Illuminate\Validation\Rule; class UpdateAssetRequest extends ImageUploadRequest { @@ -35,10 +36,29 @@ class UpdateAssetRequest extends ImageUploadRequest */ public function rules() { - $rules = array_merge( - (new Asset())->getRules(), - parent::rules(), - ); + $rules = [ + 'model_id' => 'required|integer|exists:models,id,deleted_at,NULL|not_array', + 'status_id' => 'required|integer|exists:status_labels,id', + 'asset_tag' => ['required', 'min:1', 'max:255', 'not_array', Rule::unique('assets', 'asset_tag')->ignore($this->asset)->withoutTrashed()], + 'name' => 'nullable|max:255', + 'company_id' => 'nullable|integer|exists:companies,id', + 'warranty_months' => 'nullable|numeric|digits_between:0,240', + 'last_checkout' => 'nullable|date_format:Y-m-d H:i:s', + 'expected_checkin' => 'nullable|date', + 'location_id' => 'nullable|exists:locations,id', + 'rtd_location_id' => 'nullable|exists:locations,id', + 'purchase_date' => 'nullable|date|date_format:Y-m-d', + 'serial' => 'nullable|unique_undeleted:assets,serial', + 'purchase_cost' => 'nullable|numeric|gte:0', + 'supplier_id' => 'nullable|exists:suppliers,id', + 'asset_eol_date' => 'nullable|date', + 'eol_explicit' => 'nullable|boolean', + 'byod' => 'nullable|boolean', + 'order_number' => 'nullable|string|max:191', + 'notes' => 'nullable|string|max:65535', + 'assigned_to' => 'nullable|integer', + 'requestable' => 'nullable|boolean', + ]; return $rules; } diff --git a/app/Models/Asset.php b/app/Models/Asset.php index c1ab89cb7d..3219e50e19 100644 --- a/app/Models/Asset.php +++ b/app/Models/Asset.php @@ -92,7 +92,7 @@ class Asset extends Depreciable protected $rules = [ 'model_id' => 'required|integer|exists:models,id,deleted_at,NULL|not_array', 'status_id' => 'required|integer|exists:status_labels,id', - 'asset_tag' => 'required|min:1|max:255|not_array|unique:assets,asset_tag,asset,id,deleted_at,"NULL"', + 'asset_tag' => 'required|min:1|max:255|unique_undeleted:assets,asset_tag|not_array', 'name' => 'nullable|max:255', 'company_id' => 'nullable|integer|exists:companies,id', 'warranty_months' => 'nullable|numeric|digits_between:0,240',