marick/laravel-mysql-enhanced

There is no license information available for the latest version (v1.0.0) of this package.

Add support for lateral joins and more in MySQL for Laravel

v1.0.0 2023-04-23 13:29 UTC

This package is auto-updated.

Last update: 2024-10-29 18:39:46 UTC


README

Latest Version on Packagist Tests Total Downloads

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.

Installation

composer require marick/laravel-mysql-enhanced

Features

Lateral joins

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