Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel validate error

Tags:

php

laravel

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?

like image 269
Vitalii Avatar asked Jun 20 '14 13:06

Vitalii


People also ask

How does validate work in laravel?

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.

How do I show laravel validation errors in blade?

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.

How do you validate exact words in laravel?

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.

How do you add a validation rule in laravel?

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.


2 Answers

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.

like image 144
J.T. Grimes Avatar answered Oct 06 '22 19:10

J.T. Grimes


Add this below namespace:

use Illuminate\Support\Facades\Validator;
like image 35
Mrunali Khandekar Avatar answered Oct 06 '22 18:10

Mrunali Khandekar