belongsTo(User::class); } public function scopeParent(Builder $builder) { $builder->whereNull('parent_id'); } public function children() { return $this->hasMany(Comment::class, 'parent_id')->oldest(); } public function commentable() { return $this->morphTo(); } public function parent() { return $this->hasOne(Comment::class, 'id', 'parent_id'); } // Recursevly calculates how deep the nesting is public function depth(): int { return $this->parent ? $this->parent->depth() + 1 : 0; } }