Inner Join with Multiple Conditions Example by using Query Builder in Laravel

Today now here in this post i will show how to add multiple condition in the join query of Laravel Eloquent. if we are using data relationship then we don’t need to use but if we need to get the data by using manually join with two or more condition then i hope it can help you. Now in this example i will also add how to add simple inner join in laravel and also how to add multiple conditions with inner join i mean by using “on” method.

Now you can see this on the bellow example:

Example:
$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();
print_r($user);

Read Also : How to convert Object into Array in PHP?

Thanks for read. I hope it help you. For more you can follow us on facebook.

About Shahriar Sagor

My name is Shahriar sagor. I'm a developer. I live in Bangladesh and I love to write tutorials and tips that will help to other Developer's. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.

View all posts by Shahriar Sagor →