joelharkes/laravel-model-joins

Easily join laravel models in query builder

0.0.2 2023-04-07 09:25 UTC

This package is auto-updated.

Last update: 2024-10-09 00:08:03 UTC


README

Latest Version on Packagist Build status Total Downloads

User::query()->joinMany(Transaction::class);

Installation

You can install the package via composer:

composer require joelharkes/laravel-model-joins

Usage

examples:

User::query()->joinMany(Transaction::class);
$post->user()->joinMany(Transaction::query()->withoutTrashed());
Transaction::query()->joinOne(User::class, type: 'left');
Transaction::query()->joinOne(User::query()->where('is_manager', true));

types of joins

Join a one-to-many relationship:

User::query()->joinMany(Transaction::class);

Join a x-to-one relationship:

Transaction::query()->joinOne(User::class);

All of these work well with SoftDeletes no matter if you join left, write or inner.

Join queries

Transaction::query()
    ->joinOne(User::query()->where('is_manager', true));