承接 labrodev/laravel-filter-components 相关项目开发

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

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

labrodev/laravel-filter-components

Composer 安装命令:

composer require labrodev/laravel-filter-components

包简介

Package to extend filters for CRUD (with using Spatie Laravel Query Builder)

README 文档

README

This repo is Laravel package to extend filtering functionality in Laravel projects. If you have a list with items and you use spatie/laravel-query-builder to filter them, this package could be useful for you.

This package based on spatie/laravel-query-builder use case. We express our appreciation to Spatie for inspiring us, sharing valuable experiences, and providing exceptional Laravel packages that we not only extensively use but also wholeheartedly recommend.

QueryBuilder classes

In this package you may find some custom part of Query Builder to extend filtering logic.

DateRangeFilter

QueryBuilder class which implements a logic to filter by range of dates using WhereBetween.

IsNotNullFilter

QueryBuilder class which implements a logic to filter by whereNull or whereNotNull depend on the given input value. Could be used when we just need to filter by some flag behind which there is a logic (like: Have unpaid invoices - Yes/No).

WhereInFilter

QueryBuilder class which implements a logic to filter b whereIn using given array of values (good for multiple selects as filters).

View components

Also in this package you may find filter components that render filter component depends on type and logic.

You may public vendor views from this package to implement your own styles for filter components blade templates and to adjust it to your layout and theme.

By default filter components in blade use Bootstrap classes.

Boolean filter

View component to render a filter with select options No,Yes (or custom options defined in component attribute).

Custom select filter

View component to render a filter with custom select options as filter options.

Date range filter

View component to render a filter with two date inputs as date range (start date and end date).

Input filter

View component to render a filter with text input.

Multiple select field

View component to render a filter with multiple select options from given Eloquent Model.

Select field

View component to render a filter with select options from given Eloquent Model.

Link

View component to render a sort field.

Installation

You can install the package via composer:

composer require labrodev/laravel-filter-components

Optionally, you can publish the views to implement them to your layout.

php artisan vendor:publish --tag=filter-components-views

Optionally, you can publish the view components to extend the logic you need.

php artisan vendor:publish --tag=filter-components-components

Usage

QueryBuilder classes

Let's assume that you are familiar with Spatie\QueryBuilder and already implemented filtering logic using Spatie\QueryBuilder.

You may extend usage by using QueryBuilder classes from this package: DateRangeFilter, WhereInFilter, IsNotNullFilter.

use Illuminate\Http\Request;
use Labrodev\Filters\QueryBuilder\DateRangeFilter;
use Labrodev\Filters\QueryBuilder\WhereInFilter;
use Labrodev\Filters\QueryBuilder\IsNotNullFilter;
use Spatie\QueryBuilder\AllowedFilter;
use Spatie\QueryBuilder\QueryBuilder;

class YourQuery extends QueryBuilder
{
    public function __construct(Request $request)
    {
        $query = YourModel::query();

        parent::__construct($query, $request);

        //DateRangeFilter
        $this->allowedFilters([
            AllowedFilter::custom('filter_name', new DateRangeFilter(), 'table_column') 
        ]);

        //DateRangeFilter
        $this->allowedFilters([
            AllowedFilter::custom('filter_name', new WhereInFilter(), 'table_column') 
        ]);

        //IsNotNullFilter
        $this->allowedFilters([
            AllowedFilter::custom('filter_name', new IsNotNullFilter(), 'table_column') 
        ]);
    }
}

View components

Let's consider that you want to have a filtering in your CRUD list.

There could be a filter block. Let's assume to may have a form for your filters.

<form action="your filter routing" method="GET">
<!-- and here could be components from this package -->
<button type="submit"></button>
</form>

Boolean filter

<x-filter-boolean-field 
    field="filter[{{ $filterField }}]" 
    name="{{ __('Filter label') }}" 
    options="{{__('Your option 1') }},{{ __('Your option 2')}}">
</x-filter-boolean-field>
  • field - this property is query parameter which will be in search request
  • name - this is label for this filter
  • options - options which will be in select box; if it is not provided, then it will No, Yes options by default

Custom select filter

<x-filter-custom-select-field>
    field="filter[{{ $filterField }}]"
    name="{{ __('Filter label') }}"
    options="{{__('Your option 1') }},{{ __('Your option 2')}}">
</x-filter-custom-select-field>
  • field - this property is query parameter which will be in search request
  • name - this is label for this filter
  • options - options which will be in select box

Date range filter

<x-filter-date-range-field>
    field="filter[{{ $filterField }}]"
    name="{{ __('Filter label') }}">
</x-filter-date-range-field>
  • field - this property is query parameter which will be in search request
  • name - this is label for this filter

Input filter

<x-filter-field>
    field="filter[{{ $filterField }}]"
    name="{{ __('Filter label') }}">
</x-filter-field>
  • field - this property is query parameter which will be in search request
  • name - this is label for this filter

Multiple select filter

<x-filter-multiple-select-field 
    field="filter[{{$filterField}}]"
    name="{{ __('Filter label') }}"
    class="{{ $eloquentModelClass }}"
    value="{{ $eloquentModelProperty}}">
</x-filter-multiple-select-field>
  • field - this property is query parameter which will be in search request
  • name - this is label for this filter
  • class - Eloquent model class from where will be taken values for options. For example, if class is App\Models\UserGroup, then will be rendered all user groups from user_groups table as options
  • value - property which will be shown as options. For example, if value will be name, column name from user_groups table will be used for option; if you want to split two columns to have them as option, put in value them separeted by comma: 'column1,column2'

Select filter

<x-filter-select-field 
     field="filter[{{$filterField}}]"
    name="{{ __('Filter label') }}"
    class="{{ $eloquentModelClass }}"
    value="{{ $eloquentModelProperty}}">
</x-filter-select-field>
  • field - this property is query parameter which will be in search request
  • name - this is label for this filter
  • class - Eloquent model class from where will be taken values for options. For example, if class is App\Models\UserGroup, then will be rendered all user groups from user_groups table as options
  • value - property which will be shown as options. For example, if value will be name, column name from user_groups table will be used for option; if you want to split two columns to have them as option, put in value them separeted by comma: 'column1,column2'

Link

<x-sort-link name="{{ $fieldToSort }}">
</x-sort-link>
  • name - field to sort

Testing

composer test

PhpStan check

composer analyse

Changelog

Please see CHANGELOG for more information on what has changed recently.

Credits

License

The MIT License (MIT). Please see License File for more information.

labrodev/laravel-filter-components 适用场景与选型建议

labrodev/laravel-filter-components 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 254 次下载、GitHub Stars 达 1, 最近一次更新时间为 2023 年 11 月 18 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「laravel」 「laravel-package」 「laravel-filters」 「labrodev」 「laravel-filter-components」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 labrodev/laravel-filter-components 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 labrodev/laravel-filter-components 我们能提供哪些服务?
定制开发 / 二次开发

基于 labrodev/laravel-filter-components 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-11-18