-
Notifications
You must be signed in to change notification settings - Fork 1
Right Join
Gilberto Junior edited this page Dec 5, 2019
·
6 revisions
This method defines a relationship to another table in your query.
public function rightJoin(string $table, string|array|Closure $relations): self;
public function rjoin(string $table, string|array|Closure $relations): self;
PHP's way:
$repository->rightJoin('users', 'users.id = orders.user_id');
SQL's Representation:
RIGHT JOIN
users ON users.id = orders.user_id
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
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
by c0dehappy