Strengths:
Weaknesses:
LIKE on large text fields) could degrade query performance; requires proactive indexing/DB tuning.$filter = app(Filter::class)
->add('brand', function ($query, $value) {
return $query->whereHas('brand', fn($q) => $q->where('name', $value));
});
whereIn over raw input).LIKE, full-text, or complex joins./products?brand=acme&price_min=50).where clauses, custom services).Product).czim/laravel-filter and compare performance/metrics.deprecated() helper for old filter methods to guide migration.pdo, mbstring, and json extensions are enabled (common dependencies).spatie/laravel-query-builder (feature overlap).brand → string[], price → array{min, max}).// app/Filters/ProductFilter.php
class ProductFilter extends Filter {
public function __construct() {
$this->add('brand', fn($q, $value) => $q->whereHas('brand', 'name', $value));
$this->add('price', fn($q, $range) => $q->whereBetween('price', [$range['min'], $range['max']]));
}
}
// app/Http/Controllers/ProductController.php
public function index(Request $request) {
$filter = app(ProductFilter::class)->apply($request->query());
return Product::query()->filter($filter)->get();
}
<select name="brand"> → ?brand=acme).$countableFilter = new CountableFilter(Product::query());
$countableFilter->apply($request->query());
$brandCounts = $countableFilter->getCounts('brand');
app/Filters/), reducing duplication.add('price', ..., 'numeric')).where clauses.app/Filters/Product/").toSql() to verify generated queries.$filter->debug(function ($query, $value) {
logger()->debug("Filter applied: {$query->toSql()}", ['value' => $value]);
});
with() is used for relationships (e.g., whereHas).Product filtering by Category which filters by Product).How can I help you explore Laravel packages today?