This is the error
Symfony \ Component \ Debug \ Exception \ FatalErrorException Call to undefined method Illuminate\Validation\Validator::make()
This is my code
$validator = Validator::make($userdata,$rules);
if( $validator->fails() )
{
return View::make('default::partials.user.getregistration')->withErrors($validator)->withInput();
}
What can this be?
When using the validate method during an AJAX request, Laravel will not generate a redirect response. Instead, Laravel generates a JSON response containing all of the validation errors. This JSON response will be sent with a 422 HTTP status code.
You can call any() method on $errors variable to check that there are any validation errors exist in it or not. It returns 1 if any errors exist in $errors variable. After that you can call foreach method on $errors->all() and display message using $error variable.
To get the exact words to validate you can make use of Rule::in method available with laravel. Using Rule::in method whatever the values provided by this rule has to be matched otherwise it will fail.
You should add all your validation logic in the passes() function. It should return true or false based on the logic you have written in the function. The message() function returns a string that specifies the error message to be displayed in case the validation fails.
I believe that you probably have
use Illuminate\Validation\Validator;
in your file. (Your IDE probably thought it was being helpful.) To use the static ::
call, Validator
should be aliased to Illuminate\Support\Facades\Validator
. (The \app\config\app.php file does this for you by default.)
Chances are good that changing the use statement to
use \Validator;
will fix things.
Add this below namespace:
use Illuminate\Support\Facades\Validator;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With