Laravel Join 3 Tables


Laravel Join 3 Tables: Joining more than two tables is very common in any framework, we often need to join 3 or more then three table in Laravel. Here in this tutorial we are going to explain how you can join three tables or more than three tables in Laravel.


Laravel Join 3 Tables Example | Join Multiple Tables

It is very simple to join 3 tables in Laravel. Let us create an example to join 3 table –

Laravel Join 3 Tables Example:

$orderList = DB::table('users')
    ->join('orders', 'users.id', '=', 'orders.user_id')
    ->join('order_items', 'orders.id', '=', 'order_items.orders_id')
    ->where('users.id', '=', 5)
    ->get();

The above example will join the three tables – users, orders and order_items on the basis of the foreign keys. You can join multiple tables on the same ways to get the data from different-different tables.


User Ans/Comments

Advertisements