$posts = Post::where('category_id', $category_id)->get();
if ($request->has('category_id')) {
$category_id = $request->category_id;
$posts = Post::where('category_id', $category_id)->get();
} else {
$posts = Post::all();
}
$query = Author::query();
$query->when(request('filter_by') == 'likes', function ($q) {
return $q->where('likes', '>', request('likes_amount', 0));
});
$query->when(request('filter_by') == 'date', function ($q) {
return $q->orderBy('created_at', request('ordering_rule', 'desc'));
});
$authors = $query->get();