alkhachatryan/laravel-enhanced-filters
Composer 安装命令:
composer require alkhachatryan/laravel-enhanced-filters
包简介
Extensible Laravel filtering engine with Amazon-style faceted search. Supports field types (string, numeric, boolean, date), operator-level validation, clean structured errors, and automatic query builder mapping. Perfect for APIs, dashboards, and complex multi-field filters.
README 文档
README
Want to have a filters like this? Go ahead😎
Enhanced Filters for Laravel provide a flexible, AWS-like filtering system for filtering. You can define fields, operators, and their validation rules, then use them to filter queries efficiently. ✅
It supports multiple field types, each with their own operators. The package handles validation, ensures only supported operators are used, and integrates seamlessly with Laravel request classes. 💡
Perfect for building advanced search and filter systems without writing repetitive query logic. 🚀
This is an API(backend, no UI) implementation only
Usage
Define Enhanced Filters in your Request Class
Your request class should implement HasEnhancedFilters and use EnhancedFilters trait:
<?php use Alkhachatryan\LaravelEnhancedFilters\HasEnhancedFilters; use Alkhachatryan\LaravelEnhancedFilters\Traits\EnhancedFilters; use Alkhachatryan\LaravelEnhancedFilters\FieldTypes\{ BooleanFieldType, DateFieldType, NumericFieldType, StringFieldType }; class ListBlogPostsRequest extends FormRequest implements HasEnhancedFilters { use EnhancedFilters; public function rules(): array { return [ // your basic rules 'enhancedFilters' => [new EnhancedFilterRule($this->enhancedFilters())], ]; } public function enhancedFilters(): array { return [ 'title' => new StringFieldType(['nullable', 'max:255']), 'body' => new StringFieldType(['nullable', 'max:5000']), 'author_id' => new NumericFieldType(['nullable', 'int'), 'rating' => new NumericFieldType(['nullable', 'float']), 'is_active' => new BooleanFieldType(['nullable']), 'created_at' => new DateFieldType(['nullable']), ]; } }
Call the filter class in your controller/service/business logic class
use Alkhachatryan\LaravelEnhancedFilters\QueryBuilderEnhancedFilter; // Later in the method $queryBuilderEnhancedFilter = app(QueryBuilderEnhancedFilter::class); $enhancedFilters = $request->enhancedFiltersWithValues(); $query = BlogPost::query(); // Your specific querying $queryBuilderEnhancedFilter->filter($query, $enhancedFilters); // Your ordering staff return $query->get(); // or whatever
Send your enhanced request
Installation
composer require alkhachatryan/laravel-enhanced-filters
That's it.
More about the package
So the package provides the extension for your request classes for filtering.
You will be able to filter like: FIELD - FILTERING_OPERATOR - VALUE
The package provides the following field-types:
- BooleanFieldType
- DateFieldType
- NumericFieldType
- StringFieldType
Each of them have their own specific filtering operators, but also have the common ones.
(not that true and false values(i.e. boolean) should be sent as a __true__ or __false__ strings
Common filtering operators for all field types
- equals - string/numberic value
- notEquals - string/numberic value
- isNull - __true__ or __false__
- isNotNull - __true__ or __false__
Boolean filtering operators
- isTrue - __true__ or __false__
- isFalse - __true__ or __false__
Date filtering operators
- before - a date formatted Y-m-d\TH:i:sP
- beforeOrEquals - a date formatted Y-m-d\TH:i:sP
- after - a date formatted Y-m-d\TH:i:sP
- afterOrEquals - a date formatted Y-m-d\TH:i:sP
- yearEquals - a date formatted Y
- notYearEquals - a date formatted Y
- monthEquals - a date formatted m
- notMonthEquals - a date formatted m
- dayEquals - an integer [1-31]
- notDayEquals - an integer [1-31]
- hourEquals - an integer [0-23]
- notHourEquals - an integer [0-23]
- minuteEquals - an integer [0-59]
- notMinuteEquals - an integer [0-59]
- secondEquals - an integer [0-59]
- notSecondEquals - an integer [0-59]
Numeric filtering operators
- greaterThan - numeric value
- greaterThanOrEquals - numeric value
- lessThan - numeric value
- lessThanOrEquals - numeric value
String filtering operators
- contains - string value
- notContains - string value
- startsWith - string value
- notStartsWith - string value
- endsWith - string value
- notEndsWith - string value
- lengthEquals - integer value
- lengthNotEquals - integer value
- lengthGreaterThan - integer value
- lengthLessThan - integer value
Versioning
The package has a semantic versioning X.Y.Z where X - a version of supported Laravel, Y a number of feature commits and a Z a number of bugfixes
alkhachatryan/laravel-enhanced-filters 适用场景与选型建议
alkhachatryan/laravel-enhanced-filters 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2 次下载、GitHub Stars 达 2, 最近一次更新时间为 2025 年 12 月 02 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「query」 「laravel」 「filters」 「Enhanced」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 alkhachatryan/laravel-enhanced-filters 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 alkhachatryan/laravel-enhanced-filters 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 alkhachatryan/laravel-enhanced-filters 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Simple filters for laravel
Query filtering in your frontend
Anax Database Active Record module for model classes.
Livewire Filters is a series of Livewire components that provide you with the tools to do live filtering of your data from your own Livewire components.
A lightweight WordPress hook helper library. Register hooks before WordPress loads, run callbacks only once, and more.
Database/ORM-agnostic query construction helper
统计信息
- 总下载量: 2
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 33
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Unknown
- 更新时间: 2025-12-02