Physical Address

304 North Cardinal St.
Dorchester Center, MA 02124

Indian State, City SQL Database in Laravel

Indian State, City SQL Database in Laravel

Do you want to use Indian State, City SQL Database in any application?

get all states sql database in laravel
get all cities sql database in laravel

State and City MySQL database download

In this article, we will implement the database of the Indian State and City SQL Database. The download link contains the entire database of the Indian State and city. This SQL database has a list of states, State-wise city records. It has more than 30+ state records and 6500+ city records. This you can integrate with any of your projects.

Import database without Laravel application

Create SQL Table:-

Create states Table:-

CREATE TABLE states (
   state_id int(11) NOT NULL,
   state_title varchar(50) NOT NULL,
   state_description text DEFAULT NULL,
   status varchar(10) NOT NULL
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

Create cities Table:-

CREATE TABLE cities(
   id int(11) NOT NULL,
   name varchar(100) NOT NULL,
   state_id int(11) NOT NULL,
   description text DEFAULT  NULL,
   status varchar(10) DEFAULT NULL
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

Download and Import states and cities SQL Table below:-

Indian State, City SQL Database in Laravel
Indian State, City SQL Database in Laravel

Import database with Laravel application

Indian State City SQL Database Laravel:-

Generate migration with model

php artisan make:model State -m
php artisan make:model City -m

states:-

<?php

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

return new class extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('states', function (Blueprint $table) {
            $table->id();
            $table->string('state_title');
            $table->string('state_description')->nullable();
            $table->string('status');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('states');
    }
};

cities:-

<?php

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

return new class extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('cities', function (Blueprint $table) {
            $table->id();
            $table->foreignId('state_id')->constrained('states')->onUpdate('cascade')->onDelete('cascade');
            $table->string('name');
            $table->string('description')->nullable();
            $table->string('status');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('cities');
    }
};

app\Models\City:-

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class City extends Model
{
    use HasFactory;
}

app\Models\State:-

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class State extends Model
{
    use HasFactory;
}

I hope that this article helped you learn to use and download Indian State, City SQL Database in Laravel with an Example. You may also want to check out our guide on How to Create factory in Laravel 9 application.