I've seen people on forums struggling with an error like this: "Method Illuminate\Validation\Validator::validateName does not exist". Why does it happen, and how to fix?
This happens if you use some validation rule that isn't available in the default Laravel validation rules list.
In the example above, "validateName" means that laravel is searching for a rule called "name," which, indeed, does not exist.
In another forum example, the validateRequest
error was caused by the mistype of "request" instead of "required".
All the validation rule strings like "abc_xyz" are transformed internally into a static method, validateAbcXyz
, changing snake case to camel case. For example, the rule "required_with" internally calls the method "validateRequiredWith".
Under the hood, it's handled by a Validator class that contains a "magic method" named __call()
:
public function __call($method, $parameters){ $rule = Str::snake(substr($method, 8)); if (isset($this->extensions[$rule])) { return $this->callExtension($rule, $parameters); } throw new BadMethodCallException(sprintf( 'Method %s::%s does not exist.', static::class, $method ));}
So, typically this error happens when just mistyping the validation rule name or using a rule that you think exists but doesn't.
No comments or questions yet...