<?php

namespace App\Http\Controllers;

use App\Models\News;
use Illuminate\View\View;

class NewsController extends Controller
{
    public function index(): View
    {
        $news = News::active()->published()->latest('published_at')->paginate(6);

        return view('news.index', compact('news'));
    }

    public function show(string $slug): View
    {
        $news = News::active()->published()->where('slug', $slug)->firstOrFail();
        $recent = News::active()->published()->where('id', '!=', $news->id)
            ->latest('published_at')->take(3)->get();

        return view('news.show', compact('news', 'recent'));
    }
}
