The package currently only adds support for lateral joins because is something I needed. The idea is similar to Tobias Petry's amazing package: Laravel Postgres Enhanced.
Feel free to make a PR to add more features.
composer require marick/laravel-mysql-enhanced
Available methods: joinSubLateral
, leftJoinSubLateral
User::select('users.email', 'posts.*')
->joinSubLateral(
Post::whereColumn('posts.user_id', 'users.id')
->orderBy('price', 'desc')
->limit(3),
'posts',
)
SELECT
users.email,
posts.*
FROM
users
INNER JOIN LATERAL (
SELECT *
FROM posts
WHERE posts.user_id = users.id
ORDER BY price DESC
LIMIT 3
) as posts on true