Laravel 8 Form Validation Example




Laravel 8 Form Validation Example

Hi Dev,

In this tutorial, I would like to share with you how to use form validation in laravel 8. I will let you know how to implement form input validation in laravel 8. In this tutorial, I will show you how to define laravel validation rules, how to validate form input and to display validation errors.

we will help you to give example of form validation with error message in laravel 8. In this blog, laravel 8 form validation example tutorial.

Here I will give you full example for laravel 8 form validation example. So let's follow bellow step by step.

Step 1 : Install Laravel 8

In the first step, we need to get fresh laravel 8 version application So let's open terminal and run bellow command to install fresh laravel project.

composer create-project --prefer-dist laravel/laravel blog

Step 2 : Database Configuration

In second step, we will make database Configuration for example database name, username, password etc for our crud application of laravel 8 So lets open .env file and fill all deatils like as bellow:





DB_DATABASE=here your database name(blog)

DB_USERNAME=here database username(root)

DB_PASSWORD=here database password(root)

Step 3: Add Resource Route

Here, we need to add resource route for form validation in user create. so open your "routes/web.php" file and add following route.


use App\Http\Controllers\HomeController;

Route::get('user/create', [ HomeController::class, 'create' ]);

Route::post('user/store', [ HomeController::class, 'store' ]);

Step 4: Add Controller

In this step, now we should create new controller as HomeController. So run bellow command and create new controller. bellow controller for create resource controller.

php artisan make:controller HomeController

After bellow command you will find new file in this path "app/Http/Controllers/HomeController.php".

In this controller will create seven methods by default as bellow methods:



So, let's copy bellow code and put on HomeController.php file.



namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Models\User;

class HomeController extends Controller



* Show the application dashboard.


* @return \Illuminate\Http\Response


public function create()


return view('createUser');



* Show the application dashboard.


* @return \Illuminate\Http\Response


public function store(Request $request)


$validatedData = $request->validate([

'name' => 'required',

'password' => 'required|min:5',

'email' => 'required|email|unique:users'

], [

'name.required' => 'Name is required',

'password.required' => 'Password is required'


$validatedData['password'] = bcrypt($validatedData['password']);

$user = User::create($validatedData);

return back()->with('success', 'User created successfully.');



Step 5: Add Blade Files

In last step. In this step we have to create just blade files. So mainly we have to create createUser file. So finally you have to create createUser bellow blade file:

So let's open createUser.blade.php following file and put bellow code.



<!DOCTYPE html>



<title>Laravel 8 Form Validation Example -</title>

<meta charset="utf-8">

<meta http-equiv="X-UA-Compatible" content="IE=edge">

<meta name="viewport" content="width=device-width, initial-scale=1">

<link rel="stylesheet" href="" integrity="sha512-MoRNloxbStBcD8z3M/2BmnT+rg4IsMxPkXaGh2zD6LGNNFE80W3onsAhRcMAMrSoyWL9xD7Ert0men7vR8LUZg==" crossorigin="anonymous" />



<div class="container">

<div class="row mt-5">

<div class="col-8 offset-2 mt-5">

<div class="card">

<div class="card-header bg-info">

<h3 class="text-white">Laravel 8 Form Validation Example -</h3>


<div class="card-body">


<div class="alert alert-success">

{{ Session::get('success') }}






<form method="POST" action="{{ url('user/store') }}">

{{ csrf_field() }}

<div class="form-group">


<input type="text" name="name" class="form-control" placeholder="Name">

@if ($errors->has('name'))

<span class="text-danger">{{ $errors->first('name') }}</span>



<div class="form-group">


<input type="password" name="password" class="form-control" placeholder="Password">

@if ($errors->has('password'))

<span class="text-danger">{{ $errors->first('password') }}</span>



<div class="form-group">


<input type="text" name="email" class="form-control" placeholder="Email">

@if ($errors->has('email'))

<span class="text-danger">{{ $errors->first('email') }}</span>



<div class="form-group text-center">

<button class="btn btn-success btn-submit">Save</button>










Now we are ready to run our form validation example with laravel 8 so run bellow command for quick run:

php artisan serve

Now you can open bellow URL on your browser:


You will see layout as like bellow:


It will help you...

#Laravel 8

#Laravel 7


#Laravel 6