mirror of
https://github.com/snipe/snipe-it.git
synced 2025-02-21 03:15:45 -08:00
just about wrapped up
This commit is contained in:
parent
e1fb446888
commit
52340aca78
|
@ -2,25 +2,27 @@
|
|||
|
||||
namespace App\Http\Requests\Traits;
|
||||
|
||||
use App\Models\AssetModel;
|
||||
|
||||
trait MayContainCustomFields
|
||||
{
|
||||
//public function after()
|
||||
//{
|
||||
// dd($this);
|
||||
// $request_data = $this;
|
||||
//}
|
||||
|
||||
// this gets called automatically on a form request
|
||||
public function withValidator($validator)
|
||||
{
|
||||
$validator->after(function ($validator) {
|
||||
$custom_fields = $this->collect()->keys()->filter(function ($attributes) {
|
||||
$request_fields = $this->collect()->keys()->filter(function ($attributes) {
|
||||
return str_starts_with($attributes, '_snipeit_');
|
||||
});
|
||||
if (count($custom_fields) > 0) {
|
||||
if (count($request_fields) > 0) {
|
||||
if ($this->method() == 'POST') {
|
||||
dd($this->model_id);
|
||||
$request_fields->diff(AssetModel::find($this->model_id)->fieldset->fields->pluck('db_column'))
|
||||
->each(function ($request_field_name) use ($request_fields, $validator) {
|
||||
// i could probably add some more conditions here to determine whether or not the column exists but just not on this asset model
|
||||
// and then return a more helpful error message
|
||||
$validator->errors()->add($request_field_name, 'This field does not seem to exist (at least on this asset), please double check your custom field names.');
|
||||
});
|
||||
} elseif ($this->method() == 'PUT' || $this->method() == 'PATCH') {
|
||||
dd($this->asset());
|
||||
// need to know about other pr before I can go down this route
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue