From a70506cc383b45546a1a0ccc8ab8b7987fb09f63 Mon Sep 17 00:00:00 2001 From: Jonas Staudenmeir Date: Sat, 13 Jul 2024 00:03:56 +0200 Subject: [PATCH] Support breaking change in Laravel v11.15 --- .../ConcatenatesNativeRelationships.php | 30 ++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/Eloquent/Traits/ConcatenatesNativeRelationships.php b/src/Eloquent/Traits/ConcatenatesNativeRelationships.php index 31185e5..0b3fb91 100644 --- a/src/Eloquent/Traits/ConcatenatesNativeRelationships.php +++ b/src/Eloquent/Traits/ConcatenatesNativeRelationships.php @@ -6,6 +6,7 @@ use Illuminate\Database\Eloquent\Relations\BelongsToMany; use Illuminate\Database\Eloquent\Relations\HasManyThrough; use Illuminate\Database\Eloquent\Relations\HasOneOrMany; +use Illuminate\Database\Eloquent\Relations\HasOneThrough; use Illuminate\Database\Eloquent\Relations\MorphOneOrMany; use Illuminate\Database\Eloquent\Relations\MorphToMany; use Illuminate\Database\Eloquent\Relations\Relation; @@ -132,6 +133,32 @@ protected function hasOneOrManyDeepFromHasManyThrough( return [$through, $foreignKeys, $localKeys]; } + /** + * Prepare a has-one-deep or has-many-deep relationship from an existing has-one-through relationship. + * + * @param \Illuminate\Database\Eloquent\Relations\HasOneThrough $relation + * @param \Illuminate\Database\Eloquent\Model[] $through + * @param array $foreignKeys + * @param array $localKeys + * @return array + */ + protected function hasOneOrManyDeepFromHasOneThrough( + HasOneThrough $relation, + array $through, + array $foreignKeys, + array $localKeys + ) { + $through[] = get_class($relation->getParent()); + + $foreignKeys[] = $relation->getFirstKeyName(); + $foreignKeys[] = $relation->getForeignKeyName(); + + $localKeys[] = $relation->getLocalKeyName(); + $localKeys[] = $relation->getSecondLocalKeyName(); + + return [$through, $foreignKeys, $localKeys]; + } + /** * Prepare a has-one-deep or has-many-deep relationship from an existing morph-one or morph-many relationship. * @@ -198,7 +225,8 @@ protected function hasOneOrManyDeepRelationMethod(Relation $relation) { $classes = [ BelongsTo::class, - HasManyThrough::class, + HasManyThrough::class, // TODO[L12] + HasOneThrough::class, MorphOneOrMany::class, HasOneOrMany::class, MorphToMany::class,