Country State City Dropdown using Ajax in Laravel

In this tutorial you will learn about the Country State City Dropdown using Ajax in Laravel and its application with practical example.

In this Laravel country state city dependent dropdown tutorial I’ll show you how to implement dependent country state city dropdown in laravel using jQuery ajax. In this tutorial you will learn to create country state city dropdown using jquery ajax in laravel. In this step by step tutorial I will demonstrate creating ajax country state city dropdown with example.

Country State City Dropdown using Ajax in Laravel

  • Step 1: Install Laravel App
  • Step 2: Add Database Details
  • Step 3: Create Country State City Migration and Model File
  • Step 4: Add Routes For Country State City
  • Step 5: Create Controller For Fetch Country State City
  • Step 6: Create Blade File For Show Dependent Country State City in Dropdown
  • Step 7: Run Development Server

Step 1: Install Laravel App

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

Step 2: Add Database Details

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.

Step 3: Create Country State City Migration and Model File

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

Next, Navigate to database/migrations directory and open create_country_state_city_tables.php. Then update the following code into create_country_state_city_tables.php file, as follow:

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

Step 4: Add 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

Step 5: Create Controller to Fetch Country State City

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

Then, Navigate to app/http/controllers and open CountryStateCityController.php file. And update the following code into your CountryStateCityController.php file, as follow:

Step 6: Create Blade File For Dependent Country State City Dropdown

Now, go to resources/views directory And create 1 blade views that named country-state-city.blade.php the file inside this directory.

Then open country-state-city.blade.php file and update the following code into create.blade.php file, as follow:

Now add country state city script code into your country-state-city.blade.php file, after the closing of body tag:

Step 7: 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 Country State City Dropdown using Ajax in Laravel and its application with practical example. I hope you will like this tutorial.