定制 morningtrain/laravel-filters 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

morningtrain/laravel-filters

Composer 安装命令:

composer require morningtrain/laravel-filters

包简介

Query filters for Laravel

README 文档

README

This package provides a series of filters that can be used to constrain a Laravel DB Query based on request values.

Installation

Via Composer

$ composer require morningtrain/laravel-filters

Included Filters

All filters can be used using the base Filter class at: MorningTrain\Laravel\Filters\Filter. It should not be confused with MorningTrain\Laravel\Filters\Filters\Filter that are the base class all filters are extending.

Basic

Filter by a basic variable static variable.

The following example look for filter_request_parameter in the request, and apply it to the query for the column of the same name.

Filter::by('filter_request_parameter')

It corresponds to:

$q->where(
    'filter_request_parameter', 
    '=',
    request()->get('filter_request_parameter')
)

Like in the following example, it is possible to add a closure as the second parameter.

The closure will get the query as well as the filter value as parameters. It makes it possible to apply some custom logic.

Filter::by('filter_request_parameter', function($query, $value) {
    /// Custom logic for applying $value to $query
})

Always

Always run a closure and apply something to the query.

Filter::always(function($query) {

})

With

Eager load relations on the query.

Filter::with(['company', 'roles'])

Paginate

Apply pagination to the query. It is important that this filter is applied last.

It expects the request values $page and $per_pageto be present.

Filter::paginate()

Order

The order filter can be configured to sort the data by specific columns or using scopes.

To specify the columns to sort by, call the only method on the filter. The following example will look for sort[id] and sort[created_at] in the request.

The values of sort[<column_name>] can be either asc or desc.

Filter::order()->only(['id', 'created_at'])

Calling the scope method, it is possible to also configure any scopes to be used. It will be looking in the request for any sort keys that match the scope name.

Filter::order()
    ->only(['id', 'created_at'])
    ->scopes(['orderByName'])

Default values can also easily be added:

Filter::order()
    ->only(['id', 'created_at'])
    ->scopes(['orderByName'])
    ->defaultValue(['orderByName' => 'desc'])

Credits

This package is developed and actively maintained by Morningtrain.

 _- _ -__ - -- _ _ - --- __ ----- _ --_  
(         Morningtrain, Denmark         )
 `---__- --__ _ --- _ -- ___ - - _ --_ ´ 
     o                                   
    .  ____                              
  _||__|  |  ______   ______   ______ 
 (        | |      | |      | |      |
 /-()---() ~ ()--() ~ ()--() ~ ()--() 
--------------------------------------

morningtrain/laravel-filters 适用场景与选型建议

morningtrain/laravel-filters 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.85k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2019 年 03 月 22 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: GPL-3.0-only
  • 更新时间: 2019-03-22