<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Cviebrock\EloquentSluggable\Sluggable;
use Cviebrock\EloquentSluggable\SluggableScopeHelpers;

class BlogCategory extends Model
{
    use HasFactory, Sluggable, SluggableScopeHelpers;

    protected $table = 'blog_categories';

    protected $fillable = ['name', 'slug', 'description'];

    public function sluggable(): array
    {
        return [
            'slug' => [
                'source' => 'name',
                'onUpdate' => true,
                'unique' => true,
            ],
        ];
    }

    public function posts()
    {
        return $this->belongsToMany(BlogPost::class, 'post_category', 'category_id', 'post_id');
    }
}
