Skip to content

A free open source IT asset/license management system

this is a pretty good start, need to know about other PR

spencerrlongge1fb446888ee
diff --git a/app/Http/Requests/StoreAssetRequest.php b/app/Http/Requests/StoreAssetRequest.php
index 8e7559673e..587116de42 100644
--- a/app/Http/Requests/StoreAssetRequest.php
+++ b/app/Http/Requests/StoreAssetRequest.php
@@ -2,6 +2,7 @@
namespace App\Http\Requests;
+use App\Http\Requests\Traits\MayContainCustomFields;
use App\Models\Asset;
use App\Models\Company;
use Carbon\Carbon;
@@ -10,6 +11,7 @@ use Illuminate\Support\Facades\Gate;
class StoreAssetRequest extends ImageUploadRequest
{
+ use MayContainCustomFields;
/**
* Determine if the user is authorized to make this request.
*
@@ -36,6 +38,8 @@ class StoreAssetRequest extends ImageUploadRequest
'company_id' => $idForCurrentUser,
'assigned_to' => $assigned_to ?? null,
]);
+
+ //$this->after();
}
/**
diff --git a/app/Http/Requests/Traits/MayContainCustomFields.php b/app/Http/Requests/Traits/MayContainCustomFields.php
new file mode 100644
index 0000000000..8acdacb07b
--- /dev/null
+++ b/app/Http/Requests/Traits/MayContainCustomFields.php
@@ -0,0 +1,30 @@
+<?php
+
+namespace App\Http\Requests\Traits;
+
+trait MayContainCustomFields
+{
+ //public function after()
+ //{
+ // dd($this);
+ // $request_data = $this;
+ //}
+
+ public function withValidator($validator)
+ {
+ $validator->after(function ($validator) {
+ $custom_fields = $this->collect()->keys()->filter(function ($attributes) {
+ return str_starts_with($attributes, '_snipeit_');
+ });
+ if (count($custom_fields) > 0) {
+ if ($this->method() == 'POST') {
+ dd($this->model_id);
+ } elseif ($this->method() == 'PUT' || $this->method() == 'PATCH') {
+ dd($this->asset());
+ }
+ }
+
+ });
+ }
+}
+