27 lines
527 B
PHP
27 lines
527 B
PHP
<?php
|
|||
|
|
|
||
|
|
namespace App\Http\Controllers;
|
||
|
|
|
||
|
|
use App\Models\Post;
|
||
|
|
use Illuminate\View\View;
|
||
|
|
|
||
|
|
class PostController extends Controller
|
||
|
|
{
|
||
|
|
public function index(): View
|
||
|
|
{
|
||
|
|
$posts = Post::query()
|
||
|
|
->published()
|
||
|
|
->orderByDesc('published_at')
|
||
|
|
->paginate(6);
|
||
|
|
|
||
|
|
return view('posts.index', compact('posts'));
|
||
|
|
}
|
||
|
|
|
||
|
|
public function show(Post $post): View
|
||
|
|
{
|
||
|
|
abort_unless($post->published_at?->isPast(), 404);
|
||
|
|
|
||
|
|
return view('posts.show', compact('post'));
|
||
|
|
}
|
||
|
|
}
|