Slide 1
Excellent Education Program
Innovative Methods of Teaching

Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Cum sociis natoque penatibus et magnis dis parturient.

Slide 2
Learning Through Play
Devoted to the Early Education

Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim.

Slide 2
Learning Through Play
Devoted to the Early Education

Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim.

Slide 2
Learning Through Play
Devoted to the Early Education

Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim.

Slide 2
Learning Through Play
Devoted to the Early Education

Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim.

Slide 3
Learning Through Play
Find a Class for your Children

Aenean leo ligula, porttitor eu, consequat vitae, eleifend ac, enim. Aliquam lorem ante, dapibus in, viverra quis.

previous arrow
next arrow

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

Spread the Knowledge

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')
 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]);

    }

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

Route::resource('state','StateController');
Route::any('/search1', 'StateController@search');

Run the URL

Thanks