Laravel Left Join Query Example

Laravel Left Join Query Example

In this example you learn laravel left join query example. In this post we will discuss about on how to implement laravel left join query builder. I simply explain you how to use left join in laravel. You will see how to use laravel left join using use db(), join() method.

Read Also :  CRUD with Image Upload in Laravel 8 Example

Example : Laravel Left Join Query

public function index()
    $users =DB::table('products')
            ->leftJoin('users', 'products.user_id', '=', '')
    echo '<pre>';

users Table

You have to create the users table.

users table

Products Table

product table


[0] => stdClass Object
        [id] => 1
        [name] => john
        [price] => 45000
        [image] => 1620826541.png
        [details] => dell laptop
        [user_id] => 1
        [created_at] => 
        [updated_at] => 
        [deleted_at] => 
        [email] =>
        [email_verified_at] => 
        [password] => 123456
        [remember_token] => 

I hope you understand of laravel left join query and it can help you…

Read Also :  Laravel 8 Resource Route Controller Example