Laravel provides several different approaches to validate your application's incoming data.

Create Routes

routes/web.php : In next step, we will add new two routes in web.php file.

Route::get('/', function () {
    return view('login');
});
Route::post("validation","UserController@validation");

Creating The Controller

Create a controller file UserController.php and save it in the following path app/Http/Controllers/UserController.php.

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;

class UserController extends Controller {
  
   public function validation(Request $request) {
      $this->validate($request,[
         'email'=>'required',
         'pass'=>'required'
      ]);
   }
   
}
?>

Creating The View

Create a view file login.blade.php and save the below code it in resources/views/login.blade.php.

<!DOCTYPE html>
<html>
    <head>
        <title>Login form</title>
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css">
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js"></script>
    </head>
    <body>
        <div class="container">
            <div class="row">
                <form method="post" action="validation">
                    @csrf
                    <div class="col-md-6" style="margin-top: 50px">
                        <div class="form-group {{ $errors->has('email') ? 'has-error' : '' }}">
                            Enter Your Email <span class="text-danger">{{ $errors->first('email') }}</span><br/>
                            <input type="text" name="email"class="form-control" />
                            <br/>
                        </div>
                        <div class="form-group {{ $errors->has('pass') ? 'has-error' : '' }}">
                            Enter Your Password <span class="text-danger">{{ $errors->first('pass') }}</span><br/>
                            <input type="password" name="pass" class="form-control" />
                            <br/>
                        </div>
                        <input type="submit" name="login" value="Login" class="form-control" />
                    </div>
                </form>
            </div>
        </div>
    </body>
</html>

Let us execute this example by the following URL in the browser. This URL may be different based on your website.

https://howtowebcode.com/