joelharkes / laravel-model-joins
Easily join laravel models in query builder
0.0.2
2023-04-07 09:25 UTC
Requires
- php: ^8.0
- illuminate/database: ^9.0|^10.0
Requires (Dev)
- laravel/pint: ^1.8
- orchestra/testbench: ^7.0|^8.0
- phpunit/phpunit: ^8.0|^9.0
README
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));