<?php

namespace App\Models;

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

class Blog extends Model
{
    use HasFactory;


    protected $fillable = [
        'title',
        'content',
        'author',
        'category_id',
        'tag_id',
        'image',
        'status',
        'published_at'
    ];

    public function category()
    {
        return $this->belongsTo(BlogCategory::class, 'category_id');
    }

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

    // optional scope
    public function scopePublished($query)
    {
        return $query->where('status', 'published');
    }
}
