承接 alkhachatryan/laravel-enhanced-filters 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

alkhachatryan/laravel-enhanced-filters

最新稳定版本:12.0.1

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

Latest Version on Packagist Total Downloads

image

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

The example in postman below image

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:

  1. BooleanFieldType
  2. DateFieldType
  3. NumericFieldType
  4. 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

统计信息

  • 总下载量: 2
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2025-12-02