Laravel 5 - inner join with multiple conditions example using Query Builder

By Hardik Savani | April 30, 2016 | | 96690 Viewer | Category : Laravel


In this post you can learn how to add multiple condition in join query of Laravel Eloquent. if you use data relationship then you don't need to use but if you need to get manually join with two or more condition then it can help. in this example i also add how to add simple inner join in laravel and how to add multiple conditions with inner join i mean using "on" method. You can see 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);



Hardik Savani
My name is Hardik Savani. I'm a full-stack developer, entrepreneur and owner of Aatman Infotech. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.
***Do you want me hire for your Project Work? Then Contact US.


We are Recommending you: