Replies: 2 comments 3 replies
-
Acc. to Update: But clearly is marks the user as invalid because it does have other attributes which is ok, no? The only thing missing here is the message that does not clearly explain the reason. |
Beta Was this translation helpful? Give feedback.
-
\Illuminate\Validation\Concerns\ValidatesAttributes::validateArray /**
* Validate that an attribute is an array.
*
* @param string $attribute
* @param mixed $value
* @param array $parameters
* @return bool
*/
public function validateArray($attribute, $value, $parameters = [])
{
if (! is_array($value)) {
return false;
}
if (empty($parameters)) {
return true;
}
return empty(array_diff_key($value, array_fill_keys($parameters, '')));
} as you can see the function returns only bool and then the default message is used. Throwing an exception with the message from there would mean some refactoring... |
Beta Was this translation helpful? Give feedback.
-
The available validation rules in Laravel are awesome and most of the time the error message which is shown to the client is super clear and helpful.
But recently I had a finding related to the
array
validation rule, which made me think. Can this be improved? 🤔When you are using the
array
validation rule with extra arguments, like it is also shown in the documentation, then you get a rather confusing error message.The
user
in the input is clearly an array. But it defines additional attributes which are not expected/allowed.For me this is not this 100% Laravel usually tries to deliver. Does anybody think the same? It did not dare to open a bug issue for this, as I would not really consider this as a "bug". It's more an enhancement.
I found out that the message is defined in src/Illuminate/Translation/lang/en/validation.php#L24. Does anybody have a glue how "easy" this could be improved? Or if this is even possible at all?
Beta Was this translation helpful? Give feedback.
All reactions