From 753c63349d5049910d94f497a239cb4ae904757f Mon Sep 17 00:00:00 2001 From: Sander Muller Date: Wed, 4 Sep 2024 16:58:55 +0200 Subject: [PATCH] Update BelongsToThrough.php --- src/Relations/BelongsToThrough.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Relations/BelongsToThrough.php b/src/Relations/BelongsToThrough.php index 745dcaf..6cee1f2 100644 --- a/src/Relations/BelongsToThrough.php +++ b/src/Relations/BelongsToThrough.php @@ -10,6 +10,7 @@ use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Database\Query\Expression; use Illuminate\Support\Str; +use RuntimeException; /** * @template TRelatedModel of \Illuminate\Database\Eloquent\Model @@ -341,7 +342,7 @@ public function getFirstForeignKeyName() $firstThroughParent = end($this->throughParents); if ($firstThroughParent === false) { - $firstThroughParent = $this->parent; + throw new RuntimeException('No "through" parent models were specified.'); } return $this->prefix . $this->getForeignKeyName($firstThroughParent); @@ -357,7 +358,7 @@ public function getQualifiedFirstLocalKeyName() $lastThroughParent = end($this->throughParents); if ($lastThroughParent === false) { - $lastThroughParent = $this->parent; + throw new RuntimeException('No "through" parent models were specified.'); } return $lastThroughParent->qualifyColumn($this->getLocalKeyName($lastThroughParent));