Laravel Inner Join with Multiple Conditions Example
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.....
- How to Notifications With database Driver in Laravel 11?
- How to Send Email Via Notification in Laravel 11?
- How to Install and Configure Laravel 11 Debugbar?
- How to Like Dislike System in Laravel 11?
- How to Paginate a Model with Relationship in Laravel 11?
- Laravel 11 Upload Files to Amazon S3 Example
- Laravel 11 Send WhatsApp Messages Example
- Laravel 11 Rest API Authentication Using JWT Tutorial