Get the class name for polymorphic relations.
public getMorphClass ( ) : string | ||
return | string |
use Illuminate\Database\Eloquent\Model; class Comment extends Model { public function commentable() { return $this->morphTo(); } public function getCommentableType() { return $this->commentable_type; } public function getActualCommentable() { return $this->morphTo()->newInstance(); } public function getActualCommentableId() { return $this->getActualCommentable()->getKeyName(); } }In this example, the `Comment` model has a polymorphic relationship with the `Post` and `User` models through the `commentable()` function. The `getMorphClass()` function is used here to retrieve the type of the model associated with the `Comment` model. Package/Library: Laravel Eloquent ORM.