File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed
Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change 1212use function array_diff ;
1313use function array_keys ;
1414use function config ;
15+ use function in_array ;
1516use function method_exists ;
1617use function preg_replace ;
1718
2021 */
2122trait RestrictsExtraAttributes
2223{
24+ protected bool $ checkForExtraProperties = true ;
25+ protected bool $ checkForEmptyPayload = true ;
26+ protected array $ methodsForEmptyPayload = ['PATCH ' ];
27+
2328 protected function prepareForValidation (): void
2429 {
2530 $ this ->checkForNotAllowedProperties ();
2631
32+ $ this ->checkForEmptyPayload ();
33+
2734 parent ::prepareForValidation ();
2835 }
2936
37+ private function checkForEmptyPayload (): void
38+ {
39+ if (! $ this ->checkForEmptyPayload ) {
40+ return ;
41+ }
42+
43+ if (in_array ($ this ->method (), $ this ->methodsForEmptyPayload , true )) {
44+ if (empty ($ this ->input ())) {
45+ throw ValidationException::withMessages (['general ' => [__ ('validation.payload_is_empty ' )]]);
46+ }
47+ }
48+ }
49+
3050 private function checkForNotAllowedProperties (): void
3151 {
52+ if (! $ this ->checkForExtraProperties ) {
53+ return ;
54+ }
55+
3256 $ extraAttributes = array_diff (
3357 $ this ->getValidationData (),
3458 $ this ->getAllowedAttributes (),
You can’t perform that action at this time.
0 commit comments