Skip to content

Commit a8b1a95

Browse files
committed
Add allow some extra properties
1 parent d21a434 commit a8b1a95

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/Lodash/Http/Requests/RestrictsExtraAttributes.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use function app;
1212
use function array_diff;
1313
use function array_keys;
14+
use function array_search;
1415
use function config;
1516
use function in_array;
1617
use function method_exists;
@@ -22,6 +23,7 @@
2223
trait RestrictsExtraAttributes
2324
{
2425
protected bool $checkForExtraProperties = true;
26+
protected array $ignoreExtraProperties = [];
2527
protected bool $checkForEmptyPayload = true;
2628
protected array $methodsForEmptyPayload = ['PATCH', 'POST', 'PUT'];
2729

@@ -53,8 +55,19 @@ private function checkForNotAllowedProperties(): void
5355
return;
5456
}
5557

58+
$validationData = $this->getValidationData();
59+
60+
// Ignore marked properties
61+
if (! empty($this->ignoreExtraProperties)) {
62+
foreach ($this->ignoreExtraProperties as $deleleValue) {
63+
if (($key = array_search($deleleValue, $validationData)) !== false) {
64+
unset($validationData[$key]);
65+
}
66+
}
67+
}
68+
5669
$extraAttributes = array_diff(
57-
$this->getValidationData(),
70+
$validationData,
5871
$this->getAllowedAttributes(),
5972
);
6073

0 commit comments

Comments
 (0)