Understanding Join Queries in Laravel [joins in laravel]

Today, We want to share with you joins in laravel.In this post we will show you Laravel 6 Joins Example Tutorial, hear for join laravel we will give you demo and example for implement.In this post, we will learn about Sub Query Joins with an example.

laravel join query

  • Inner Join Clause
  • Left Join / Right Join Clause
  • Cross Join Clause
  • Advanced Join Clauses
  • Sub-Query Joins
Read Also:  Delete All Files from Folder with PHP

Inner Join Clause

$member = Member::join('gifts', 'gifts.member_id', '=', 'members.id')
       ->select('members.*')
       ->get();

Left Join / Right Join Clause

Left Join Clause

 Member::leftJoin('gifts', 'gifts.member_id', '=', 'members.id')
       ->select('members.*')
       ->get();

Right Join Clause

Member::rightJoin('gifts', 'gifts.member_id', '=', 'members.id')
       ->select('members.*')
       ->get();

Cross Join Clause

Size::crossJoin('colours')
     ->get();

Advanced Join Clauses

DB::table('members')
        ->join('calls', function ($join) {
            $join->on('members.id', '=', 'calls.member_id')
                 ->where('calls.member_id', '>', 5);
        })
        ->get();

Sub-Query Joins

DB::table('gifts')
->select('member_id', DB::raw('MAX(created_at) as last_post_created_at'))
->where('is_published', true)->groupBy('member_id');


I hope you get an idea about laravel joins.
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.