MYHOSPITALNOW.COM

Find Trusted Doctors & Hospitals

Discover healthcare providers, compare hospitals, and explore treatment options worldwide.

Free Treatment Quotes • Doctor Search • Hospital Comparison

Find Healthcare Options

www.myhospitalnow.com

How to Store Countries, States, Cities seed classes into the Database in Laravel PHP? (Part-2)

How to Store Countries, States, Cities seed classes into the Database in Laravel PHP?

Part-1 Part-3

Laravel DropDown Feature page with empty Country, State and City select fields

Step 1. Create a State seeder file. Write down the following command as follows:

$  php artisan make:seeder StatesTableSeeder
Git Bash running php artisan make:seeder StatesTableSeeder with Seeder created successfully

Step 2. Create a State model. Write down the following command as follows:

$  php artisan make:model State -m
Git Bash terminal running php artisan make:model State -m in the country_state_city project

Step 3. Add columns into Country table.

 public function up()
    {
        Schema::create('states', function (Blueprint $table) {
           $table->bigIncrements('state_id');
            $table->string('state_name');
            $table->integer('country_id');
            $table->timestamps();
        });
    }Code language: PHP (php)

Step 4. Go to Database/seeds/DatabaseSeeder file. Write down the following command as follows to add State seeder class:

 public function run()
    {
        $this->call(CountriesTableSeeder::class);
        $this->call(StatesTableSeeder::class);
    }Code language: PHP (php)

Step 5. Go to Database/seeds/CountriesTableSeeder file.

Step 6. Migrate the tables into the MySQL database.

$ php artisan migrate

Step 7. Run the seeder class file individually.

$  php artisan db:seed --class=StatesTableSeederCode language: JavaScript (javascript)

Step 8. Go to app\http\Controllers\MainController.php file. Define funcitions of Country and State.

Step 9. Then, go to routes/web.php file and define all these routes.

Route::get('/getStates/{id}','MainController@getStates');Code language: JavaScript (javascript)
DropDown Feature with India selected and State dropdown listing Indian states, Jharkhand highlighted

Thanks

Find Trusted Cardiac Hospitals

Compare heart hospitals by city and services — all in one place.

Explore Hospitals
With MotoShare.in, you can book a bike instantly, enjoy doorstep delivery, and ride without worries. Perfect for travelers, professionals, and adventure enthusiasts looking for a seamless mobility solution.

Related Posts

How to display a table in a Verticle or Horizontal form in the Laravel PHP Framework? Part-1

How to display a table in a Verticle or Horizontal form in the Laravel PHP Framework? How to Store Seed file into Database. Click There are two…

Read More

HOW TO CREATE EVENT CALENDAR IN LARAVEL? PART-3

Step 1.Create a Database in phpMyAdmin. (Write the same name of database which was written in .enf databse name). Step 2.  We use the migrate command to…

Read More

HOW TO CREATE EVENT CALENDAR IN LARAVEL? PART-2

Step 1.Create a Laravel Project Firstly, Create a new project in laravel, so we open Git Bash,  Go to My Computer/This PC–>LocalDisk(C:)–>Xampp–>Htdocs (Press right click on Mouse)…

Read More

How to file upload in DB With local folder using laravel 5.8

Step:1 you have to make these(A) – php artisan make:controller ImageUploadController(B) – php artisan make:model ImageUpload -m Step:2 Open the welcome.blade.php page then write this code. Step:3…

Read More

How to Store Countries, States, Cities seed classes into the Database in Laravel PHP? (Part-3)

How to Store Countries, States, Cities seed classes into the Database in Laravel PHP Part-1 Part- 2 Step 1. Create a City seeder file. Write down the…

Read More

How to Store Countries, States, Cities seed classes into the Database in Laravel PHP? (Part-1)

How to Store Countries, States, Cities seed classes into the Database in Laravel PHP? Part- 2 Part- 3 Step 1. Create a Country seeder file. Write down…

Read More