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

This commit is contained in:
spencerrlongg 2024-04-04 14:20:03 -05:00
parent e5800a2dac
commit e1fb446888
2 changed files with 34 additions and 0 deletions

View file

@ -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();
}
/**

View file

@ -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());
}
}
});
}
}