Download the PHP package mpyw/eloquent-has-by-join without Composer
On this page you can find all versions of the php package mpyw/eloquent-has-by-join. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package eloquent-has-by-join
Eloquent Has By Join
Convert has()
and whereHas()
constraints to join()
ones for single-result relations.
[!IMPORTANT] NOTICE: Postgres' optimizer is very smart and covers JOIN optimization for dependent (correlated) subqueries. Therefore, this library is mainly targeted at MySQL which has a poor optimizer.
[!CAUTION] UPDATE: MySQL's optimizer has also been updated in version
8.0.16
to include optimizations similar to PostgreSQL. This library is no longer maintained.
Requirements
- PHP:
^7.3 || ^8.0
- Laravel:
^6.0 || ^7.0 || ^8.0 || ^9.0 || ^10.0
Installing
Motivation
Suppose you have the following relationship:
If you use has()
constraints, your actual query would have dependent subqueries.
These subqueries may cause performance degradations.
This package provides Illuminate\Database\Eloquent\Builder::hasByJoin()
macro to solve this problem:
you can easily transform dependent subqueries into simple JOIN queries.
API
Signature
Arguments
$relationMethod
A relation method name that returns a BelongsTo
, HasOne
or MorphOne
instance.
You can pass nested relations as an array or a string with dot-chain syntax.
You can provide table aliases with "as"
syntax.
$constraints
Additional callable
constraints for relations that take Illuminate\Database\Eloquent\Builder
as the first argument.
The first closure corresponds to post
and the second one corresponds to author
.
Feature Comparison
Feature | mpyw/eloquent-has-by-join |
mpyw/eloquent-has-by-non-dependent-subquery |
---|---|---|
Minimum Laravel version | 5.6 | 5.8 |
Argument of optional constraints | Illuminate\Database\Eloquent\Builder |
Illuminate\Database\Eloquent\Relations\* ( Builder can be also accepted by specifying argument type) |
Compoships support | ✅ | ❌ |
No subqueries | ✅ | ❌ (Performance depends on database optimizers) |
No table collisions | ❌ (Sometimes you need to give aliases) |
✅ |
No column collisions | ❌ (Sometimes you need to use qualified column names) |
✅ |
OR conditions | ❌ | ✅ |
Negative conditions | ❌ | ✅ |
Counting conditions | ❌ | ❌ |
HasOne |
✅ | ✅ |
HasMany |
❌ | ✅ |
BelongsTo |
✅ | ✅ |
BelongsToMany |
❌ | ✅ |
MorphOne |
✅ | ✅ |
MorphMany |
❌ | ✅ |
MorphTo |
❌ | ❌ |
MorphMany |
❌ | ✅ |
MorphToMany |
❌ | ✅ |
HasOneThrough |
❌ | ✅ |
HasManyThrough |
❌ | ✅ |
All versions of eloquent-has-by-join with dependencies
illuminate/database Version ^6.0 || ^7.0 || ^8.0 || ^9.0 || ^10.0
illuminate/support Version ^6.0 || ^7.0 || ^8.0 || ^9.0 || ^10.0