In this video we are going to learn about form validation.
in laravel form validation is used to ensure all required form controls are filled out, in the correct format.
Now lets see how we can apply the validation to form.
So switch to project.
Now click on login view.
In this view file you can see the email field and password field.
Lets open this in browser.
So go to the browser and just type here /login.
Now if I'm not going to provide any validation.
Then user can put any thing inside the input box.
Like put here assdf.
which is not a valid email address.
Without validation when I click on submit button.
it will be submitted which is not good.
So to ensure all the filled are filled out in the correct format we use form validation.
Now I'm going to put the validation with this form.
So go to the LoginController and inside the loginSubmit method write the following code.


public function loginSubmit(Request $request)
{
$validatedData = $request->validate([
'email' => 'required|email',
'password' => 'required|min:6|max:12'
]);
$email = $request->input('email');
$password = $request->input('password');
return 'Email : '.$email. ' Password : '.$password;
}



Now go to the login.blade.php view file.
Here lets display validation error message.
so for that add the following code after email and password input field.


@error('email') {{message}} @enderror

@error('password') {{message}} @enderror


Now save the view and switch to browser and refresh the page.
Now enter some invalid data and click on submit.
You can see here it is showing some validation error.
Error message must be in red color.
So for that just add a css in head.


<style>
.error{
color:red;
}
</style>


Refresh the page re-enter the invalid data.
Ok now error message showing in red color now we put valid value in both field and click on submit.
Now you can see here form has been submitted successfully.
So in this way you can add the form validation with the form in laravel 8.