承接 kalimeromk/filterable 相关项目开发

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

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

kalimeromk/filterable

Composer 安装命令:

composer require kalimeromk/filterable

包简介

A Laravel package that simplifies dynamic filtering and searching across models and their relationships, eliminating repetitive query code.

关键字:

README 文档

README

Filterable is a Laravel package designed to simplify dynamic filtering and searching across models and their relationships, eliminating the need for repetitive query code. It provides an easy-to-use trait and macros for building powerful, dynamic query filters.

Installation

  1. Require the package via Composer:

    composer require kalimeromk/filterable
  2. The package supports auto-discovery, so no manual registration of the service provider is needed. However, if you are using an older Laravel version, add the service provider to your config/app.php:

    'providers' => [
        Kalimeromk\Filterable\PackageServiceProvider::class,
    ];

Usage

1. Using whereLike Macro

The whereLike macro allows you to perform "LIKE" searches on multiple fields, including related model fields.

Example:

use App\Models\User;

$users = User::query()
    ->whereLike(['name', 'email'], 'John')
    ->get();

This will return all users where the name or email fields contain the string "John".

Searching on Related Models:

$users = User::query()
    ->whereLike(['posts.title', 'posts.content'], 'Laravel')
    ->with('posts')
    ->get();

This will return all users who have posts with a title or content containing the string "Laravel".

2. Using the Filterable Trait

The Filterable trait allows you to dynamically filter a model based on specific criteria, including LIKE queries, boolean fields, and whereIn filters, as well as range filters like _min and _max.

Setup:

Add the Filterable trait to your model:

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Kalimeromk\Filterable\Traits\Filterable;

class User extends Model
{
    use Filterable;

    protected $fillable = ['name', 'email', 'is_active'];

    // Define fields for specific filters
    protected $boolFields = ['is_active'];
    protected $likeFields = ['name', 'email'];
}

Example Controller:

use App\Models\User;
use Illuminate\Http\Request;

class UserController extends Controller
{
    public function index(Request $request)
    {
        $filters = $request->only(['name', 'email', 'is_active', 'age_min', 'age_max']);

        $users = User::filter($filters)->get();

        return response()->json($users);
    }
}

Example API Request:

  • Request:
    GET /users?name=Jane&is_active=true&age_min=25&age_max=35
    
  • Result: Returns all active users (is_active = true) whose name contains "Jane" and whose age is between 25 and 35.

Testing the Package

This package uses Orchestra Testbench for testing.

Running Tests

To run the tests:

  1. Install the dependencies:

    composer install
  2. Run PHPUnit:

    vendor/bin/phpunit

License

This package is open-sourced software licensed under the MIT license.

kalimeromk/filterable 适用场景与选型建议

kalimeromk/filterable 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.73k 次下载、GitHub Stars 达 5, 最近一次更新时间为 2022 年 07 月 30 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 kalimeromk/filterable 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-07-30