Laravel Inner Join with Multiple Conditions Example

Laravel 6 , Laravel , Laravel 7

Nicesnippets

17435

10-02-2020


This tutorial will give you example of inner join condition in laravel. i explained simply about inner join in laravel eloquent i explained simply step by step laravel 6 eloquent join tables you will learn laravel inner join multiple on So, let's follow few step to create example of laravel inner join example.

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. You can see bellow example:

Example 1:

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

}

It will help you.....


Recommended Posts