Skip to main content
Tutorial Free

Laravel Validator Method Does Not Exist: How To Fix?

July 19, 2023
2 min read

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.

Enjoyed This Tutorial?

Get access to all premium tutorials, video and text courses, and exclusive Laravel resources. Join our community of 10,000+ developers.

Comments & Discussion

No comments yet…

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.