<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class Comment extends Model
{
    protected $fillable = [
        'name',
        'email',
        'website',
        'content',
        'active',
        'published_at',
        'post_id',
        'parent_id',
    ];
    public function post(): BelongsTo
    {
        return $this->belongsTo(Post::class);
    }
    public function replies()
    {
        return $this->hasMany(Comment::class, 'parent_id')->with('replies');
    }
    public function parent()
    {
        return $this->belongsTo(Comment::class, 'parent_id');
    }
}
