<?php

namespace App\Http\Controllers;

use App\Models\Page;
use Illuminate\Http\Request;
use Illuminate\View\View;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;

class PageController extends Controller
{
    /**
     * Display a listing of the resource.
     */
    public function index(): View
    {
        $pages = Page::query()
            ->where('active', 1)
            ->orderBy('created_at', 'desc')
            ->paginate(5);

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

    /**
     * Display the specified resource.
     */
    public function show(Page $page): View
    {
        if (!$page->active) {
            throw new NotFoundHttpException();
        }

        return view('page.view', compact('page'));
    }
}
