Skip to content

Commit cc646f1

Browse files
committed
Add getMorphClass method
1 parent f6e3282 commit cc646f1

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/Inheritance.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,22 @@ public function getForeignKey()
176176
return Str::snake(class_basename($this->getRootClass())).'_'.$this->getKeyName();
177177
}
178178

179+
/**
180+
* Get the class name for polymorphic relations.
181+
*
182+
* @return string
183+
*/
184+
public function getMorphClass()
185+
{
186+
$class = $this->getRootClass();
187+
188+
if ($class === static::class) {
189+
return parent::getMorphClass();
190+
}
191+
192+
return (new $class)->getMorphClass();
193+
}
194+
179195
/**
180196
* Get the class name of the root class.
181197
*

0 commit comments

Comments
 (0)