koufax's avatar

Custom Validators not working

Hey everyone,

I am having issues in my Lumen (v5.2.*) application with custom validators. I have a custom Validation Service Provider that I initialize in my app.php file. The Validation Service Provider is where I add my custom validators.

I created a custom validator called 'validateProductTypeId' that I would like to call from another Service Provider (named OrderServiceProvider). I am validating the incoming request from within the Order Service Provider, but I am getting the following message: "Method validateProductTypeId does not exist."

My validation method has 'validate' prepended to it, so I am not sure why I am getting this error. Within my app.php, I am also registering my ValidationServiceProvider before my OrderServiceProvider.

Here is a paste of my code: http://laravel.io/bin/324K3

Any help is greatly appreciated, thanks!

0 likes
1 reply
koufax's avatar

To anyone stuck as well, this is how I fixed my problem:

Replaced the following in the Service Provider:

$this->validator = $app['validator']->make($app->request->all(), $request->rules(), $request->messages());

With:

$this->validator = Validator::make($app->request->all(), $request->rules(), $request->messages());

And be sure to add the following to the top of the file:

use Validator;

Please or to participate in this conversation.