<?php

declare(strict_types=1);


namespace App\Models;

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

class Category extends Model
{
    use HasFactory;

    protected $fillable = [
        'name',
        'slug',
        'display_order',
        'post_count',
    ];

    public function posts(): HasMany
    {
        return $this->hasMany(Post::class);
    }

    public function getUrlAttribute(): string
    {
        return route('category.show', $this->slug ?? $this->id);
    }
}
