Laravel 7 Form Validation Example

Admin   Laravel   651  2021-03-17 13:20:04

Hi Guys,

Now, let's see article of form validation in laravel 7. you will learn simple form validation laravel 7.

You will learn laravel 7 form validation example. we will help you to give example of form validation with error message in laravel 7.

Step 1 : Install Laravel project

In this step you can install fresh laravel project to using bellow command.


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

Step 2 : Create Migration & Model

Now you will bellow command to create migration and model in laravel app.


php artisan make:model User -m

Above command to create one table migration file and one model file.




use Illuminate\Database\Migrations\Migration;

use Illuminate\Database\Schema\Blueprint;

use Illuminate\Support\Facades\Schema;

class CreateUsersTable extends Migration



* Run the migrations.


* @return void


public function up()


Schema::create('users', function (Blueprint $table) {










* Reverse the migrations.


* @return void


public function down()





Bellow command to use migrate your table.


php artisan migrate

Step 3 : Create Controller

In this step create controler file to use bellow command.


php artisan make:controller UserController

Step 4 : Create Controller method

Create controller after you can put the bellow code in controller file.




namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\User;

class UserController extends Controller


public function create()


return view('create');


public function store(Request $request)


$input = $request->all();


'name' => 'required',

'email' => 'required|email',

'mobile_no' => 'required|min:10|numeric',

'password' => 'required|min:6'



return back()

->with('success','User Created Successfully');



Step 5 : Create Routes

In this step you will create route in web.php file.



Route::get('form-validation','[email protected]')->name('user.create');

Route::post('form-validation','[email protected]')->name('');

Step 6 : Create View File

In this step you can create blade file in laravel app.



<!DOCTYPE html>



<title>Laravel 7 Form Validation</title>

<link rel="stylesheet" href="" target="_blank" rel="nofollow" integrity="sha256-L/W5Wfqfa0sdBNIKN9cG6QA5F2qx4qICmU2VgLruv9Y=" crossorigin="anonymous" />


<body class="bg-dark">

<div class="container">

<div class="row">

<div class="col-md-6 offset-3 mt-5">

<div class="card">

<div class="card-header">

<h5>Laravel 7 Form Validation - </h5>


<div class="card-body">

@if (count($errors) > 0)

<div class="alert alert-danger">


@foreach ($errors->all() as $error)

<li>{{ $error }}</li>





@if ($message = Session::get('success'))

<div class="alert alert-success alert-block">

<button type="button" class="close" data-dismiss="alert">×</button>

<strong>{{ $message }}</strong>



<form action="{{ route('') }}" method="post" enctype="multipart/form-data">


<div class="form-group">

<label><strong>Name : </strong></label>

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


<div class="form-group">

<label><strong>Email : </strong></label>

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


<div class="form-group">

<label><strong>Mobile No : </strong></label>

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


<div class="form-group">

<label><strong>Password : </strong></label>

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


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

<input type="submit" class="btn btn-success" name="submit" value="Save">










It will help you...