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 merge two or multiple tables to each other in the Laravel PHP Framework? (Part-1)

How to merge two or multiple tables to each other in the Laravel PHP Framework?

Part-2 Part-3

How to seed Country/State data into the Database? Click Here Here, we are going to merge the Country table to the State table using left join

The LEFT JOIN keyword returns all records from the left table (table1), and the matched records from the right table (table2). The result is NULL from the right side if there is no match.

Venn diagram of A LEFT JOIN B returning all rows of table A: 1, 2, 3, 4

Step 1. Create a new Project in Laravel, so open git bash. Write down the following command:-

$ composer create-project --prefer-dist laravel/laravel Join "5.8.*"Code language: JavaScript (javascript)

Step 2. Create the authentication scaffolding and Country model. Write down the following command:-

$ php artisan make:auth
$ php artisan make:model Country -m

Step 3. Create the State model. Write down the following command:-

$ php artisan make:model State -m

Step 4. Generate a migration file into the database/migrations folder of the Country table.

public function up()
{
        Schema::create('countries', function (Blueprint $table) {
            $table->bigIncrements('country_id');
            $table->string('country_name');
            $table->string('sort');
            $table->integer('phoneCode'); 
            $table->timestamps();
        });
    }Code language: PHP (php)

Step 5. Generate a migration file into the database/migrations folder of State 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 6. Migrate these tables into the MySQL database, so write the following command.

$ php artisan migrate

Step 7.  Create a CountryController in App/Http/Controller folder so, write the following command.

$ php artisan make:controller CountryController --resource
Git Bash running php artisan make:controller CountryController, showing Controller created successfully

Step 8. Create a StateController in App/Http/Controller folder so, write the following command.

$ php artisan make:controller StateController --resource
Git Bash running php artisan make:controller StateController, showing Controller created successfully

Step 9.  Create child file resources/views/Country folder with name create.blade.php. 

Step 10. Create an index.blade.php file within resource/views/Country/ folder.

Step 11. Create edit.blade.php file. In this file within resources/views/Country folder.

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

Laravel: oauth_access_tokens clean up process

using Laravel Passport—the oauth_access_tokens table balloons when tokens aren’t expiring, not being revoked on logout, or not being purged. Here’s a practical, safe cleanup + prevention plan…

Read More

Laravel: Complete Guide of Laravel Passport

Here’s a comprehensive, up-to-date step-by-step tutorial for setting up and using Laravel Passport (OAuth2 API authentication) with clear explanations, working code samples, and troubleshooting tips—suitable for local…

Read More

Laravel: What is APP_KEY in Laravel?

Let’s break down both what APP_KEY is in a Laravel .env file, why it matters, and its use cases. I’ll also explain how it’s generated and what…

Read More

artisan Tutorials: php artisan passport

When you run php artisan passport:install, Laravel attempts to do the following: Running php artisan passport:install is a crucial setup step when using Laravel Passport for API…

Read More

An introduction of Laravel Boilerplate

Laravel Boilerplate is a comprehensive starter kit designed to accelerate the development of Laravel applications by providing a robust foundation with pre-integrated features. Developed by Rappasoft, it…

Read More

Why You Should Avoid Laravel Spark and Stripe/Paddle for Certain Use Cases

✅ Explains why Laravel Spark is not suitable in certain use cases✅ Clarifies the limitations of Stripe and Paddle✅ Lists unsupported countries✅ Guides developers toward the right…

Read More