diff --git a/packages/graphql/src/SortBy/Sorters/EloquentSorter.php b/packages/graphql/src/SortBy/Sorters/EloquentSorter.php index cd1cff506..97aad0a6f 100644 --- a/packages/graphql/src/SortBy/Sorters/EloquentSorter.php +++ b/packages/graphql/src/SortBy/Sorters/EloquentSorter.php @@ -8,6 +8,7 @@ use Illuminate\Database\Eloquent\Relations\BelongsToMany; use Illuminate\Database\Eloquent\Relations\HasManyThrough; use Illuminate\Database\Eloquent\Relations\HasOneOrMany; +use Illuminate\Database\Eloquent\Relations\HasOneOrManyThrough; use Illuminate\Database\Eloquent\Relations\MorphOneOrMany; use Illuminate\Database\Eloquent\Relations\Relation; use Illuminate\Database\Query\JoinClause; @@ -19,6 +20,7 @@ use Override; use function array_shift; +use function class_exists; /** * @extends DatabaseSorter> @@ -157,7 +159,12 @@ static function (JoinClause $join) use ($relation, $currentAlias, $parentAlias): ? "{$parentAlias}.{$relation->getLocalKeyName()}" : $relation->getQualifiedParentKeyName(), ); - } elseif ($relation instanceof HasManyThrough) { + } elseif ( + $relation instanceof HasManyThrough + || ( // Since Laravel v11.15.0 + class_exists(HasOneOrManyThrough::class) && $relation instanceof HasOneOrManyThrough + ) + ) { $builder->joinSub( $relation->getQuery()->select([ "{$relation->getParent()->getQualifiedKeyName()} as {$currentAlias}_key",