Skip to content

Commit 1d3a599

Browse files
committed
Merge branch 'hafezdivandari/9.x' into 9.x
2 parents 7e3c959 + e4f1318 commit 1d3a599

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/Illuminate/Database/Eloquent/Concerns/HasRelationships.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ protected function newHasOne(Builder $query, Model $parent, $foreignKey, $localK
115115
*/
116116
public function hasOneThrough($related, $through, $firstKey = null, $secondKey = null, $localKey = null, $secondLocalKey = null)
117117
{
118-
$through = new $through;
118+
$through = $this->newRelatedThroughInstance($through);
119119

120120
$firstKey = $firstKey ?: $this->getForeignKey();
121121

@@ -387,7 +387,7 @@ protected function newHasMany(Builder $query, Model $parent, $foreignKey, $local
387387
*/
388388
public function hasManyThrough($related, $through, $firstKey = null, $secondKey = null, $localKey = null, $secondLocalKey = null)
389389
{
390-
$through = new $through;
390+
$through = $this->newRelatedThroughInstance($through);
391391

392392
$firstKey = $firstKey ?: $this->getForeignKey();
393393

@@ -759,6 +759,17 @@ protected function newRelatedInstance($class)
759759
});
760760
}
761761

762+
/**
763+
* Create a new model instance for a related "through" model.
764+
*
765+
* @param string $class
766+
* @return mixed
767+
*/
768+
protected function newRelatedThroughInstance($class)
769+
{
770+
return new $class;
771+
}
772+
762773
/**
763774
* Get all the loaded relations for the instance.
764775
*

0 commit comments

Comments
 (0)