Skip to content

Right Join

Gilberto Junior edited this page Dec 5, 2019 · 6 revisions

This method defines a relationship to another table in your query.

Syntax

public function rightJoin(string $table, string|array|Closure $relations): self;

Alias

public function rjoin(string $table, string|array|Closure $relations): self;

Example 1

PHP's way:

$repository->rightJoin('users', 'users.id = orders.user_id');

SQL's Representation:

RIGHT JOIN
  users ON users.id = orders.user_id

Example 2

PHP's way:

$repository->rightJoin('products', [
    'brands.id' => 'products.brand_id',
    'categories.id' => 'products.category_id',
]);

SQL's Representation:

RIGHT JOIN
  products ON brands.id = products.brand_id AND
  categories.id = products.category_id

Example 3

PHP's way:

$repository->rightJoin('orders', function ($repository) {
    $repository->on('orders.id', '=', 'order_items.order_id');
});

SQL's Representation:

RIGHT JOIN
  orders ON orders.id = order_items.order_id

🡄 Left Join | Where 🡆