diff --git a/src/Relations/BelongsToThrough.php b/src/Relations/BelongsToThrough.php index 924e870..09c0b41 100644 --- a/src/Relations/BelongsToThrough.php +++ b/src/Relations/BelongsToThrough.php @@ -335,9 +335,12 @@ public function getThroughParents() */ public function getFirstForeignKeyName() { - /** @var \Illuminate\Database\Eloquent\Model $firstThroughParent */ $firstThroughParent = end($this->throughParents); + if ($firstThroughParent === false) { + $firstThroughParent = $this->parent; + } + return $this->prefix . $this->getForeignKeyName($firstThroughParent); } @@ -348,9 +351,12 @@ public function getFirstForeignKeyName() */ public function getQualifiedFirstLocalKeyName() { - /** @var \Illuminate\Database\Eloquent\Model $lastThroughParent */ $lastThroughParent = end($this->throughParents); + if ($lastThroughParent === false) { + $lastThroughParent = $this->parent; + } + return $lastThroughParent->qualifyColumn($this->getLocalKeyName($lastThroughParent)); }