<?php

declare(strict_types=1);


namespace App\Blog\Controllers;

use App\Models\Post;

class SearchController extends Controller
{
    public function index()
    {
        $keyword = trim(request('q', request('keyword', '')));

        $posts = Post::query()
            ->published()
            ->search($keyword)
            ->orderByDesc('published_at')
            ->paginate((int) blog_setting('per_page', config('blog.per_page')));

        return theme_view('search', compact('posts', 'keyword'));
    }
}
