Find the Best Cosmetic Hospitals

Explore trusted cosmetic hospitals and make a confident choice for your transformation.

“Invest in yourself — your confidence is always worth it.”

Explore Cosmetic Hospitals

Start your journey today — compare options in one place.

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

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

$  php artisan make:seeder StatesTableSeeder

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

$  php artisan make:model State -m

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)

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

Ansible: Deep Dive into Jinja2 Ansible Template with example

Introduction to Ansible Templates and Jinja2 Ansible templates are powerful tools for creating dynamic configuration files and scripts based on variables and logic. Templates in Ansible use…

Read More

Complete User Guide for 404 Errors

Introduction A 404 error (also known as “404 Not Found”) is an HTTP status code indicating that a requested webpage cannot be found on the server. This…

Read More

What is Laravel and use cases of Laravel?

What is Laravel? Laravel is an open-source, free PHP web framework designed for the development of web applications following the model-view-controller (MVC) architectural pattern. It was generated…

Read More

What is SQL Server and use cases of SQL Server?

What is SQL Server? SQL Server, developed by Microsoft, is a relational database management system (RDBMS) that is designed to store and retrieve data requested by other…

Read More

Terrafrom – Example Code for remote-exec, local-exec & file provisioner

Rajesh Kumar I’m a DevOps/SRE/DevSecOps/Cloud Expert passionate about sharing knowledge and experiences. I have worked at Cotocus. I share tech blog at DevOps School, travel stories at…

Read More

What is SQL and use cases of SQL?

What is SQL? SQL stands for Structured Query Language. It is a powerful programming language that allows users to interact with relational databases. It provides a standardized…

Read More