ensi/laravel-query-builder-helpers 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

ensi/laravel-query-builder-helpers

最新稳定版本:0.1.14

Composer 安装命令:

composer require ensi/laravel-query-builder-helpers

包简介

This package contains extensions for laravel-query-builder

README 文档

README

Latest Version on Packagist Tests Total Downloads

The laravel-query-builder-helper package is a set of classes that simplify the creation of available filters for the laravel-query-builder package from Spatie.

Installation

You can install the package via composer:

composer require ensi/laravel-query-builder-helpers

Version Compatibility

Laravel query builder helpers Laravel PHP
^0.1.0 ^9.x ^8.1
^0.1.4 ^9.x || ^10.x ^8.1
^0.1.7 ^9.x || ^10.x || ^11.x ^8.1
^0.1.14 ^9.x || ^10.x || ^11.x || ^12.x ^8.1

Basic Usage

Creating a filter

Filters are created by applying the static make method and then calling the chain of filter methods.

use Ensi\QueryBuilderHelpers\Filters\StringFilter;

StringFilter::make('name')->contain()->endWith()->empty();

The following filter classes are currently available:

  • StringFilter
  • NumericFilter
  • DateFilter
  • PlugFilter (a stub for passing additional parameters to another filter)
  • ExtraFilter (described in the section "Additional filters")

Each filter type has its own suffix, which is added to the name passed to the make method. For example, by default, the filter empty has the suffix _empty, and the filter gt is _gt:

NumericFilter::make('rank')->exact()->empty()->gt()->lt();

As a result, we will get four filtering options available for search queries.

  • rank
  • rank_empty
  • rank_gt
  • rank_lt

Passing filters to the allowed Filters method

To transfer the received filters to the allowedFilters method of the Spatie package, the array will need to be destructured.

$this->allowedFilters([
    ...NumericFilter::make('rank')->exact()->empty()->gt()->lt(),
]);

Additional filters

The ExtraFilter class is used by the aforementioned classes, but can also be used separately.

Useful methods include:

  • nested (registers a set of nested filters)
  • predefined (creates a predefined filter that includes complex filtering)
  • and others
...ExtraFilter::nested('page', [
    ...InputFilter::make('title', 'page_title')->empty()->exact()->contain(),
]),

Configuration

In the file **config.php ** you can customize the applied suffixes. You can also set up the like operator used in search queries there.

'suffixes' => [
    'equal' => '',
    'greater' => '_gt',
    'less' => '_lt',
    ...
],

'like_operator' => 'LIKE',

Contributing

Please see CONTRIBUTING for details.

Testing

  1. composer install
  2. composer test

By default, testing takes place using in-memory DataBase SQLite. SQLite does not support some functions, for example: json_contains. To test these functions, copy phpunit.xml.dist to phpunit.xml and specify the configuration with connection to another database in the php section. When writing such tests, use the skip function to skip tests using the default connection.

->skip(fn () => DB::getDriverName() === 'sqlite', 'db driver does not support this test');

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

License

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-05-02