Skip to content

Commit

Permalink
Use the newRelatedThroughInstance method to prepare the through par…
Browse files Browse the repository at this point in the history
…ents (#154)

* use `newRelatedThroughInstance` method

* check if method exists to support older versions
  • Loading branch information
hafezdivandari committed Mar 15, 2022
1 parent 54a1a84 commit db9b0da
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/HasRelationships.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,9 @@ protected function hasOneOrManyDeepThroughParents(array $through)
$segments = preg_split('/\s+as\s+/i', $class);

$instance = Str::contains($segments[0], '\\')
? new $segments[0]()
? (method_exists($this, 'newRelatedThroughInstance')
? $this->newRelatedThroughInstance($segments[0])
: new $segments[0]())
: (new Pivot())->setTable($segments[0]);

if (isset($segments[1])) {
Expand Down

0 comments on commit db9b0da

Please sign in to comment.