<?php

namespace App\Http\Controllers;

use App\Models\Post;
use Illuminate\View\View;

class PostController extends Controller
{
    public function index(): View
    {
        return view('posts.index', ['posts' => Post::published()->orderByDesc('published_at')->orderByDesc('id')->paginate(18)]);
    }

    public function show(Post $post): View
    {
        abort_unless($post->is_published && (! $post->published_at || $post->published_at->isPast()), 404);

        return view('posts.show', compact('post'));
    }
}
