πŸš€ DevOps & SRE Certification Program πŸ“… Starting: 1st of Every Month 🀝 +91 8409492687 πŸ” Contact@DevOpsSchool.com

Upgrade & Secure Your Future with DevOps, SRE, DevSecOps, MLOps!

We spend hours on Instagram and YouTube and waste money on coffee and fast food, but won’t spend 30 minutes a day learning skills to boost our careers.
Master in DevOps, SRE, DevSecOps & MLOps!

Learn from Guru Rajesh Kumar and double your salary in just one year.


Get Started Now!

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.

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:-

See the code below:–

//My form function starts
public function myform()
{
return view("form.myform");
}
// Submit my form function Starts
public function submitmyform(request $request)
{
$validator = Validator::make($request->all(),[
"name"=>"required",
"email"=>"required|email|min:8|",
"age"=>"required"
],[
"name.required"=>"Name Should be filled",
"email.min"=>" Email length should be more than 8",
"email.email"=>"Enter a Valid E-mail"
]);
if($validator->fails()){
return redirect("/myform")->withErrors($validator);
}else{
die("Form Submitted");
}

Output

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

Output

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

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

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

Certification Courses

DevOpsSchool has introduced a series of professional certification courses designed to enhance your skills and expertise in cutting-edge technologies and methodologies. Whether you are aiming to excel in development, security, or operations, these certifications provide a comprehensive learning experience. Explore the following programs:

DevOps Certification, SRE Certification, and DevSecOps Certification by DevOpsSchool

Explore our DevOps Certification, SRE Certification, and DevSecOps Certification programs at DevOpsSchool. Gain the expertise needed to excel in your career with hands-on training and globally recognized certifications.