Laravel 10 Form Validation Example




Laravel 10 Form Validation Example

>Hi Friends,

Today our leading topic is laravel 10 form validation tutorial. you'll learn laravel 10 form validation with the error message. Here you will learn form validation laravel 10 then i will give simple example with solution. you will learn custom error messages in laravel 10 form validation.

You can also define custom error messages in laravel 10 form validation. we will display an error message with each field. we will use has() for checking is the error message in laravel 10.

Here, i am going to show you very simple example of form validation so, you can simply use it in your laravel 10 project.

Step 1: Download Laravel

Let us begin the tutorial by installing a new laravel application. if you have already created the project, then skip following step.

composer create-project laravel/laravel example-app

Step 2: Add Routes:


use Illuminate\Support\Facades\Route;

use App\Http\Controllers\StudentController;



| Web Routes



| Here is where you can register web routes for your application. These

| routes are loaded by the RouteServiceProvider within a group which

| contains the "web" middleware group. Now create something great!





Step 3: Add Controller:

Now we will add two controller method, one will just display blade file with get request, and another for post request, i write validation for that, so simply add both following method on it.



namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Models\Student;

class StudentController extends Controller



* Show the application dashboard.


* @return \Illuminate\Http\Response


public function create()


return view('createStudent');



* 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 = Student::create($validatedData);

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



Step 4: Add Blade File:

now here we will create createUser.blade.php file and here we will create bootstrap simple form with error validation message. So, let's create following file:


<!DOCTYPE html>



<title>Laravel 10 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 href="" rel="stylesheet">



<div class="container">

<div class="row justify-content-center mt-5">

<div class="col-md-8 mt-5">

<h3>Laravel 10 Form Validation Example -</h3>


<div class="alert alert-success">

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






<form method="post" action="{{ route('') }}" class="mt-4">

{{ csrf_field() }}

<div class="form-group mb-3">


<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 mb-3">


<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 mb-3">


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

<button class="btn btn-success btn-submit btn-sm">Submit</button>








Run Laravel App:

All steps have been done, now you have to type the given command and hit enter to run the laravel app:

php artisan serve

Now, you have to open web browser, type the given URL and view the app output:



I hope it can help you...

#Laravel 10