In this example, you learn the laravel left join query example. In this post we will discuss about on how to implement laravel left join query builder. I simply explain to you how to use left join in laravel. You will see how to use the laravel left join using the use DB(), join() method.
Example : Laravel Left Join Query
public function index()
{
$users =DB::table('products')
->leftJoin('users', 'products.user_id', '=', 'users.id')
->get();
echo '<pre>';
print_r($users);
exit;
}
users Table
You have to create the users table.
Output
[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] => man@gmail.com
[email_verified_at] =>
[password] => 123456
[remember_token] =>
)