Join WhatsApp ChannelJoin Now

Laravel 8 Inner Join with Multiple Conditions

Hi,

Today, i we will show you laravel 8 inner join with multiple conditions. This article will give you simple example of laravel 8 inner join with multiple conditions. you will learn laravel 8 inner join with multiple conditions.

if you employ information relationship then you do not got to use however if you would like to induce manually be part of with 2 or a lot of condition then it will facilitate.

So let’s follow few step to create example of laravel 8 inner join with multiple conditions.

Example:

SQL Query:

select `users`.*, `items`.`id` as `itemId`, `jobs`.`id` as `jobId` 
from `users` 
inner join `items` 
on `items`.`user_id` = `users`.`id` inner join `jobs`
on `jobs`.`user_id` = `users`.`id` and `jobs`.`item_id` = `items`.`id`

Laravel Query:

public function index()
{
    $user = User::select("users.*","items.id as itemId","jobs.id as jobId")
                ->join("items","items.user_id","=","users.id")
                ->join("jobs",function($join){
                    $join->on("jobs.user_id","=","users.id")
                        ->on("jobs.item_id","=","items.id");
                })
                ->get();
    dd($user);
}

I hope it will assist you…

Recommended Posts