Laravel eloquent join with condition

Today, We want to share with you Laravel eloquent join with condition.In this post we will show you Laravel Inner Join with Multiple Conditions Example, hear for Laravel Eloquent inner join with multiple conditions we will give you demo and example for implement.In this post, we will learn about A join with additional condition using Query Builder with an example.

Laravel eloquent join with condition

There are the Following The simple About Join or Left Join only with where condition in laravel 6 Full Information With Example and source code.

As I will cover this Post with live Working example to develop how to use join with where condition in laravel, so the laravel 6.2 join multiple conditions is used for this example is following below.

Example 1: inner join condition in laravel

Laravel Eloquent inner join with multiple conditions

return $query->join('members', function($join)
 {
   $join->on('members.id', '=', 'categories.shop_id');

 })
 ->select('id','status','url','owner_name','city','menus') 
 ->where('members.active', 1)
 ->get();

Example 2: laravel 6 query builder join

Laravel – Inner Join with Multiple Conditions Example using Query Builder

$member = Member::select("members.*","products.id as itemId","services.id as jobId")
            ->join("products","products.member_id","=","members.id")
            ->join("services",function($join){
                $join->on("services.member_id","=","members.id")
                    ->on("services.item_id","=","products.id");
            })
            ->get();
print_r($member);

Example 3: Join with multiple condition in eloquent

using SQL Query

select tasks.id, members.firstname, members.lastname, activities.actity_id 
from tasks
join members on (tasks.member_id = members.id)
left join activities on (tasks.id = activities.actity_id AND activities.entity_type = 'order' AND activities.name  = 'email_sent_order_payment_reminder')
   where tasks.status = 'created'
   and tasks.created_at <= (CURRENT_DATE - INTERVAL '3 day')::date
   and activities.actity_id is null

using Laravel Eloquent Query

$tasks = $this->order
            ->select(['tasks.*'])
            ->join('members', 'members.id', '=', 'tasks.member_id')
            ->leftJoin('activities', function($join) {
                $join->on('tasks.id', '=', 'activities.actity_id');
                $join->where('activities.name', '=', EventsLog::EVENT_EMAIL_SENT_ORDER_PAYMENT_REMINDER);
                $join->where('activities.entity_type', '=', 'order');
            })
            ->where('tasks.status', Task::STATUS_CREATED)
            ->where('tasks.created_at', '<=', Carbon::now()->subDay($days))
            ->whereNull('activities.actity_id')
            ->get();

return $tasks;
Web Programming Tutorials Example with Demo

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about laravel eloquent join 4 tables.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Leave a Comment