MYHOSPITALNOW.COM

Find Trusted Doctors & Hospitals

Discover healthcare providers, compare hospitals, and explore treatment options worldwide.

Free Treatment Quotes • Doctor Search • Hospital Comparison

Find Healthcare Options

www.myhospitalnow.com

Request Validation using Custom Validator in Laravel.

To use the custom validator, first, we have to load it in our controller by writing use Validator.

ProductController.php with use Validator line added to load the Laravel Validator

After that, we have to use make method of validator in which we pass all the parameters of the request object, in the second parameter we pass our validation rules and, in the third parameter we pass our custom messages.
If any error found in the object or parameter then, fails() catch it and redirects to the same page with all errors else print the given output. See below:-

Validator::make in controller with validation rules, custom messages, fails redirect and Form Submitted output

See the code below:–

Output

See when we provide invalid email then our customised message appears or not:-

Laravel form submitted with invalid email dgdcmkduid returns the Enter a Valid E-mail message

Output

Now See the output whether it returns a message when we did not provide value in the given field.

Empty form submitted, showing required-field errors for name, email and age

Now, When we fill 1-2 field and left other then what message returns. See below:-

Form with age left blank returns The age field is required and keeps the filled values

When we fill all the fields, then what returns:-

All form fields filled and submitted, so submitmyform shows Form Submitted

Find Trusted Cardiac Hospitals

Compare heart hospitals by city and services — all in one place.

Explore Hospitals
With MotoShare.in, you can book a bike instantly, enjoy doorstep delivery, and ride without worries. Perfect for travelers, professionals, and adventure enthusiasts looking for a seamless mobility solution.

Related Posts

[SOLVED] ErrorException preg_match(): No ending delimiter ‘/’ found

I’m working on Laravel 5.8. I’m trying to use Validator to validate a name field with regex, here is my rule below:   But as soon as…

Read More

Create Laravel multiple upload images and Displaying on view

Today , We will build a simple multiple images upload system using Laravel 5.8. We will use a jQuery plugin to populate image field and submit the multiple images to…

Read More

Special Characters Not Allowed Validation in Laravel 5.8

 let’s see example of laravel validation no special characters. Example -1 use this code for validation:-  ‘name’ =>  ‘required|regex:/^[a-zA-Z]+$/u’ Example:2- Use this code for validation:- ‘applyjobsforuser’ => ‘required|unique:applyjobs,applyjobsforuser’, Example-3 use this code…

Read More

Request Validation in Laravel.

Request Validation using ValidatesRequest Trait in Laravel. (Click to Open) Request Validation using Form Request in Laravel. (Click to Open) Request Validation using Custom Validator in Laravel….

Read More

How to Create a Simple Login Authentication System in LARAVEL?Part-2

How to Create a Simple Login Authentication System in LARAVEL? Firstly, Visit this Blog Part-1. Step 15. Now add these classes within MainController file. Step 16. Create…

Read More

[SOLVED] Laravel Error: Integrity constraint violation: 1062 Duplicate entry

This Error is found when we insert duplicate data which already exist in the database. To overcome from it just make the key_name unique in Validation. See…

Read More