diff --git a/app/Http/Controllers/PostController.php b/app/Http/Controllers/PostController.php index 50d4e5a..035feec 100644 --- a/app/Http/Controllers/PostController.php +++ b/app/Http/Controllers/PostController.php @@ -26,23 +26,17 @@ public function index(Request $request): View $posts = Post::query() ->select('id', 'title', 'is_featured', 'category_id', 'created_at', 'updated_at') ->withAggregate('category', 'title') - ->when($request->string('search')->toString(), function (PostBuilder $query, string $search): void { - $query->search($search); - }) + ->when($request->string('search')->toString(), fn (PostBuilder $query, $search): PostBuilder => $query->search($search)) ->when($request->input('published'), fn (PostBuilder $query): PostBuilder => $query->published()) ->when( in_array($request->input('sortBy'), PostSortColumnsEnum::columns(), true), - function (PostBuilder $query) use ($request): void { - $query->sortBy($request->string('sortBy')->toString(), $request->string('direction')->toString()); - }, - fn (PostBuilder $query) => $query->latest(), + fn (PostBuilder $query): PostBuilder => $query->sortBy($request->string('sortBy')->toString(), $request->string('direction')->toString()), + fn (PostBuilder $query) => $query->latest() ) ->paginate(10) ->withQueryString(); - return view('posts.index', [ - 'posts' => $posts, - ]); + return view('posts.index', ['posts' => $posts]); } /**