Laravel 6 validation with error message

  • 22-03-2022
  • 959
  • Laravel 6
  • Haresh Chauhan

Watch Youtube Video (HINDI) :

In this tutorial, I will teach you how it works laravel 6 validation with the error message. Laravel 6 provides default validation functions like required, exists, unique, URL, nullable, etc. I will give you some tips on laravel validation and what is the procedure to set a custom message. I will give some steps with an example.

Step 1 : Clone fresh laravel application

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

After clone laravel fresh aplication composer install and generate application key using this command.

php artisan key:generate

Step 2 : Now we move on project directory


Route::post('form/save',['as'=>'', 'uses'=>'UserController@saveForm']);

Step 3 : Create controller

php artisan make:controller UserController 


namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Controllers\FrontController;
use App\User;

class UserController extends Controller
    public function form(){       
        return view('form');
    public function saveForm(Request $request){
        $input = $request->all();   
        $validator = $this->validate($request,[
            'fullname' => 'required',
            'email' => 'required|unique|email',
            // Here you can set a custom message.
            'fullname.required' => 'This fullname must be required.',
            'email.required' => 'This email must be required.',
            '' => 'Please enter valid email',
        return redirect()->route('form');

Now here we are required to submit form so create that.

How To Clone Laravel

In this step we will create form file

Step 4 : Create form


<!DOCTYPE html>
    <title>Validation - Tutorial</title>
           @foreach ($errors->all() as $error)
              <li>{{ $error }}</li>
    <form method="post" action="{{ route('') }}">
        {{ csrf_field() }}
        <label>Fullname : </label>
        <input type="text" name="fullname">
        <label>Email : </label>
        <input type="email" name="email">

        <button type="submit">Submit</button>

You can use also individual laravel validation like this.

@if($errors->has('fullname')) {{ $errors->first('fullname') }} @endif
@if($errors->has('email')) {{ $errors->first('email') }} @endif

Here you can also check this laravel more Validation

Hope, it can help you for better laravel validation learning.

We always thanks to you for reading our blogs.


Dharmesh Chauhan

(Swapinfoway Founder)

Hello Sir, We are brothers origin from Gujarat India, Fullstack developers working together since 2016. We have lots of skills in web development in different technologies here I mention PHP, Laravel, Javascript, Vuejs, Ajax, API, Payment Gateway Integration, Database, HTML5, CSS3, and Server Administration. So you need our service Please Contact Us


Haresh Chauhan


We Are Also Recommending You :