mirror of
https://github.com/snipe/snipe-it.git
synced 2025-02-02 08:21:09 -08:00
this is a pretty good start, need to know about other PR
This commit is contained in:
parent
e5800a2dac
commit
e1fb446888
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
namespace App\Http\Requests;
|
namespace App\Http\Requests;
|
||||||
|
|
||||||
|
use App\Http\Requests\Traits\MayContainCustomFields;
|
||||||
use App\Models\Asset;
|
use App\Models\Asset;
|
||||||
use App\Models\Company;
|
use App\Models\Company;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
|
@ -10,6 +11,7 @@ use Illuminate\Support\Facades\Gate;
|
||||||
|
|
||||||
class StoreAssetRequest extends ImageUploadRequest
|
class StoreAssetRequest extends ImageUploadRequest
|
||||||
{
|
{
|
||||||
|
use MayContainCustomFields;
|
||||||
/**
|
/**
|
||||||
* Determine if the user is authorized to make this request.
|
* Determine if the user is authorized to make this request.
|
||||||
*
|
*
|
||||||
|
@ -36,6 +38,8 @@ class StoreAssetRequest extends ImageUploadRequest
|
||||||
'company_id' => $idForCurrentUser,
|
'company_id' => $idForCurrentUser,
|
||||||
'assigned_to' => $assigned_to ?? null,
|
'assigned_to' => $assigned_to ?? null,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
//$this->after();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
30
app/Http/Requests/Traits/MayContainCustomFields.php
Normal file
30
app/Http/Requests/Traits/MayContainCustomFields.php
Normal 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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue