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-3)

Part-1 Part-2

Now, we’ll create the 2nd table State to merge with the Country table.

Step 1. Create child file resources/views/State folder with name create.blade.php.

Step 2. Create edit.blade.php file. In this file within resources/views/State folder.

Step 3. Create an index.blade.php file within resource/views/State/ folder.

Step 4. Go to app/State.php. Now, we need to list all the properties we need in the $fillable array.

Step 5. Go to app/Http/Controllers/StateController.php file.

 ->leftJoin('countries', 'states.country_id', '=', 'countries.country_id')Code language: PHP (php)
 public function index()
    {
         $states = State::all()->toArray();
         $states = DB::table('states')
         ->leftJoin('countries', 'states.country_id', '=', 'countries.country_id')
         ->orderBy('state_id','desc')->paginate(5);
        return view('state.index',  ['states' => $states]);

    }Code language: PHP (php)

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

Route::resource('state','StateController');
Route::any('/search1', 'StateController@search');Code language: PHP (php)

Run the URL

Laravel State Data page listing countries and states with search, Edit and Delete buttons and pagination

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 Delete Multiple Records using Checkbox in Laravel?

It’s almost need to give feature for remove multiple records using checkbox, if you are developing e-commerce application or any big web application then you must give…

Read More

How to Display Recent and popular data from Database using left join and OderBy

Fist Step In Welcome.blade.php file for Table Secound Step In Pages.blade.php Third Step In Routing, Go To web.php Forth Step In GestController.php This is Return $gallery View…

Read More

Basic Things To Find Error In Laravel

To be master in finding error and build logic to make query, certain things should understand properly (i) check wheather your routing working properly or controller working…

Read More

CRUD Operations in Laravel PHP Framework

Step 1 – Download Laravel 5.8 In first step you have to download Laravel 5.8 version. For this you have to go to command prompt, in which…

Read More

How to merge two or multiple tables to each other in the Laravel PHP Framework? (Part-2)

How to merge two or multiple tables to each other in the Laravel PHP Framework? Part-1 Part-3 Step 1. Go to app/Country.php. Now, we need to list…

Read More

How to Use Search Functionality with Pagination in Laravel PHP Framework? Part 1

How to use Search Functionality with Pagination in Laravel PHP Framework? We are going to use Search Functionality with Pagination within the CRUD table. Click for the…

Read More