Skip to content

Commit

Permalink
validate fields from invalid
Browse files Browse the repository at this point in the history
  • Loading branch information
arif-rh committed May 1, 2020
1 parent 6c82d7a commit 9515aa9
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/Models/DynaModelTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,8 @@ public function findAll(int $limit = 0, int $offset = 0)
*/
protected function doProtectFields(array $data): array
{
$data = $this->validateFields($data);

if (! empty($this->protectedFields))
{
foreach ($data as $key => $val)
Expand All @@ -254,9 +256,30 @@ protected function doProtectFields(array $data): array
}
}
}

return parent::doProtectFields($data);
}

/**
* Make sure to remove invalid fields
*
* @param mixed[] $data
*
* @return mixed[]
*/
protected function validateFields(array $data): array
{
foreach ($data as $key => $val)
{
if (! array_key_exists($key, $this->fieldInfo))
{
unset($data[$key]);
}
}

return $data;
}

/**
* Set the value of allowedFields
*
Expand Down

0 comments on commit 9515aa9

Please sign in to comment.