<?php

declare(strict_types=1);


namespace App\Blog\Controllers;

use App\Models\Category;
use App\Models\Post;

class CategoryController extends Controller
{
    public function show(string $slug)
    {
        $category = Category::query()->where('slug', $slug)->orWhere('id', (int) $slug)->firstOrFail();

        $posts = $category->posts()
            ->published()
            ->latest('published_at')
            ->paginate((int) blog_setting('per_page', config('blog.per_page')));

        return theme_view('list', compact('category', 'posts'));
    }
}
