How to Add Exists Validation in Laravel 8 Input Field

In this tutorial you will learn about the How to Add Exists Validation in Laravel 8 Input Field and its application with practical example.

In this How to Add Exists Validation in Laravel 8 Input Field tutorial, we will learn how to add already exists validation in the laravel form. In this tutorial you will learn to use already exists validation rules in laravel form input field. In this article I will share example to use already exists validation rules in laravel form. We will implement server side validation for already exists validation rules in laravel. Suppose if you want to check the student name already exists in database table before you want to save it in database. In this case we can use exists validation rule to check if student with given name is already exists in database.

How to Add Exists Validation in Laravel 8 Input Field

In this step by step tutorial I will demonstrate you with example how to add and use exists validation rules in laravel forms. Please follow the instruction given below:

  • Step 1: Create Laravel Project
  • Step 2: Add Database Credentials
  • Step 3: Build Model and Migration
  • Step 4: Run Database Migration
  • Step 5: Create Controller File
  • Step 6: Register New Routes
  • Step 7: Create Blade View File
  • Step 8: Test Laravel App

Create Laravel Project

First of all we need to create a fresh laravel project, download and install Laravel 8 using the below command

Add Database Credentials

Now, lets create a MySQL database and connect it with laravel application. After creating database we need to set database credential in application’s .env file.

Build Model and Migration

Now, in this step we will create model and migration file. Please run the following command:

Now, open app/Student.php model file and put the following code in it:

Open create_students_table.php migration file and update the function up() method as following:

Run Database Migration

Now, run the migration to create database table using following artisan command:

Create Controller File

Now, lets create a controller named StudentController using command given below –

Now, add the code in the app/Http/Controller/StudentController.php.

Register New Routes

After this, we need to define routes in “routes/web.php” file. Lets open “routes/web.php” file and add the following routes in it.

routes/web.php

Create Blade View File

In this step we will create a blade view file, open the resources/views/welcome.blade.php file and put the following code in it:

Run Development Server

Now we are ready to run our example so lets start the development server using following artisan command –

Now, open the following URL in browser to see the output –

In this tutorial we have learn about the How to Add Exists Validation in Laravel 8 Input Field and its application with practical example. I hope you will like this tutorial.