How to Implement Exists Validation in Laravel 9 Form

Last updated on: by Digamber

This tutorial will teach you how to implement existing validation in the laravel form using the laravel exists method.

Laravel ecosystem is developer-friendly at the same time, helps web developers to build desired functionality effortlessly.

For example, building forms and adding validation in laravel is easy with a validator in this laravel exists validator example.

We will create a basic form with the title property and check if the title property exists in the database table. In general the EXISTS operator is used to check for the existence of any record in a subquery.

Similarly, The exists() field explicitly checks the field under validation rule concerning a given database table. If, anyhow, the column option is not defined, the field name will be used.

Laravel 9 Exists Validation Example

  • Step 1: Download New Laravel App
  • Step 2: Database Connection
  • Step 3: Create Migration and Model
  • Step 4: Setting Up Controller
  • Step 5: Create Routes
  • Step 5: Set Up Blade View Template
  • Step 6: View App

Download New Laravel App

No matter on which machine you are creating the laravel app, one thing is imperative that you have to install Composer globally.

After doing the needful, lay the foundation of this tutorial by installing the fresh laravel application.

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

Database Connection

In this step, you have to make the database connection by adding the database details in .env file.


Create Migration and Model

In this step, we will run the command and generate migration and model files.

php artisan make:model Blog -m

Get into the database/migrations/create_blogs_table.php and insert the values as suggested.

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateBlogsTable extends Migration
     * Run the migrations.
     * @return void
    public function up()
        Schema::create('blogs', function (Blueprint $table) {
     * Reverse the migrations.
     * @return void
    public function down()

Similar value has to be updated inside the app/Blog.php file.

namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Blog extends Model
    use HasFactory;
    public $fillable = [

Initialize the migration using the php artisan command.

php artisan migrate

Setting Up Controller

Get into the terminal and run the command to generate a new controller.

php artisan make:controller BlogController

Head over to the new controller on the following path, the app/Http/Controller/BlogController.php file and update the given code into it.

namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\Blog;

class BlogController extends Controller
    public function index() {
        return view('index');
    public function store(Request $request) {
       $validator = $this->validate($request, [
          'title' => 'required|exists:blogs,created_at'
       if($validator) {
       return back()->with('success', 'Blog created.');

Create Routes

In the next step, you have to go to routes/web.php and create the routes for handling view and laravel exists validation.

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\BlogController;

| 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!
Route::get('/', [
Route::post('validate-exists', [

Set Up Blade View Template

Go to resources/views/ directory, after that create a index.blade.php within this file define the following code.

<!DOCTYPE html>
    <meta charset="utf-8">
    <title>Integrate Exists Validation in Laravel</title>
    <link href="" rel="stylesheet">
    <div class="container mt-5">
        <form action="{{ route('validate.exists') }}" method="post">
            <div class="form-group">
                <input class="form-control" name="title" value="{{ old('title') }}">
                  <span class="text-danger">{{ $errors->first('title') }}</span>
            <div class="d-grid mt-3">
                <button class="btn btn-dark">Submit</button>

We are using the global old helper; it helps display the old input within a blade template.

You can define the database column name that should be used by the validation rule by appending it right after the database table name.

Also, instead of specifying the table name directly, you may specify the Eloquent model which should be used to determine the table name.

'id' => 'exists:App\Models\Blog,id'

Start Laravel Application

Last but not least start the laravel app using the following command.

php artisan serve

You can open the app on the following url for testing the form.

How to Implement Exists Validation in Laravel Form


In this tutorial, we have learned how to validate an input field value with the laravel exists method. Moreover, looked at how the basic usage of exists rule is applied in laravel.


I am Digamber, a full-stack developer and fitness aficionado. I created this site to bestow my coding experience with newbie programmers. I love to write on JavaScript, ECMAScript, React, Angular, Vue, Laravel.