<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class BlogPost extends Model
{
    use SoftDeletes, HasFactory;
    protected $fillable = [
        'title',
        'slug',
        'category_id',
        'post_by',
        'content',
        'post_image',
        'status',
        'published_at',
        'meta_title',
        'meta_description',
        'is_featured',
        'meta_keywords'
    ];
    protected $casts = [
        'published_at' => 'date',
    ];


    // Corrected relationship name
    public function comments()
    {
        return $this->hasMany(Comment::class);
    }

    public function category()
    {
        return $this->belongsTo(Category::class);
    }

    public function user()
    {
        return $this->belongsTo(User::class);
    }

    public function media()
    {
        return $this->hasMany(Media::class);
    }


public function tags()
{
    return $this->belongsToMany(Tag::class, 'post_tag', 'post_id', 'tag_id');
}


    public function author()
    {
        return $this->belongsTo(User::class, 'post_by');
    }
}
