sofronz/elysia 问题修复 & 功能扩展

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

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

sofronz/elysia

Composer 安装命令:

composer require sofronz/elysia

包简介

A powerful, customizable query string filter package for Laravel that lets you filter, sort, and search models using query parameters — without writing repetitive query logic.

README 文档

README

A powerful, customizable query string filter package for Laravel that lets you filter, sort, and search models using query parameters — without writing repetitive query logic.

🚀 Features

  • 🔄 Sort by fields with ease
  • 🔎 Search using LIKE
  • 📥 Filter with IN clause
  • 🎯 Supports custom query string mapping per model
  • 🧩 Fully extensible and easy to integrate
  • 🧼 Clean, well-structured codebase

📦 Installation

composer require sofronz/elysia

🛠️ Configuration

Publish the config (optional):

php artisan vendor:publish --provider="Sofronz\Elysia\ElysiaServiceProvider" --tag="config"

config/elysia.php:

return [
    'models' => [
        'user' => App\Models\User::class,
        'post' => App\Models\Post::class,
    ],
];

⚙️ Usage

In your controller:

use Sofronz\Elysia\Facades\Filter;
use App\Models\User;

public function index()
{
    $filteredUsers = Filter::model('user')->apply(User::query())->get();

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

🔁 Custom Query Parameters

By default, the Filter package applies filters using query parameters such as ?field_sort=field_name, ?field_like=value, and ?field_in=value1,value2. However, you can customize the query parameter names directly in your model.

Step 1: Add getQueryStringMapping Method in the Model

To customize the query parameters, implement a getQueryStringMapping method in your model. This method should return an array where the keys are the custom query parameters, and the values are the corresponding model fields.

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class YourModel extends Model
{
    /**
     * Map query string parameters to model attributes.
     *
     * @return array
     */
    public static function getQueryStringMapping(): array
    {
        return [
            'name_search' => 'name',  // custom query parameter `name_search` maps to `name` field
            'email_like' => 'email',  // custom query parameter `email_like` maps to `email` field
            'status_in' => 'status',  // custom query parameter `status_in` maps to `status` field
            'created_at_sort' => 'created_at',  // custom query parameter `created_at_sort` maps to `created_at` field
        ];
    }
}

In the example above, the custom query parameters are:

  • name_search will filter by name field.
  • email_like will perform a LIKE search on the email field.
  • status_in will filter by status field using the IN clause.
  • created_at_sort will sort by created_at field.

Step 2: Apply the Filters with Custom Query Parameters

Now that you've defined custom query parameters in the model, you can use them directly in the request.

Example:

GET /your-model?name=John&email=john.doe%40example.com&status=active,inactive&created_at=-created_at

This will:

  • Search for records where the name field contains "John".
  • Perform a LIKE search on the email field.
  • Filter records where the status is either "active" or "inactive".
  • Sort the records by the created_at field in descending order.

Available Filters

  • Sort: Add a custom query parameter like ?field_sort=field_name to apply sorting.
  • LIKE: Add a custom query parameter like ?field_like=value to perform a LIKE search.
  • IN: Add a custom query parameter like ?field_in=value1,value2 to filter using the IN clause.
  • Basic Where: Add custom query filters by passing fields that exist in the model's $fillable attribute.

By using the getQueryStringMapping method, you can easily customize and map query parameters to any field in your model, giving you full control over how filters are applied in your application.

🙌 Shout Out

Special thanks to ChatGPT 🤖 for assisting with the design and development of this package.

If you like my work or find it useful, you can support me through:

Buy Me a Coffee
Saweria

👨‍💻 Author

Sofronius Ruddy (GitHub: @sofronz)
Copyright (c) 2025
All rights reserved.

📝 License

MIT © 2025 Sofronz/Elysia. All rights reserved.

sofronz/elysia 适用场景与选型建议

sofronz/elysia 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 04 月 17 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-04-17