定制 theoluirard/laravel-get-easy-query 二次开发

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

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

theoluirard/laravel-get-easy-query

Composer 安装命令:

composer require theoluirard/laravel-get-easy-query

包简介

A Laravel package to easily get a query with parameters from a request.

README 文档

README

This package provides a trait that allows to construct query based on a strctured array (from a request for example)

Features

  • Implement a methods to filters, select, sort and apply 'with' methods Eloquent query

Installation

To install the package, use the following command:

composer require theoLuirard/laravel-get-easy-query 

Configuration

Add the trait to your model

Simply add the trait to your model definition

<?php

namespace App\Models;

use theoLuirard\getEasyQuery\Traits\getEasyQuery;
use Illuminate\Database\Eloquent\Model;

class MyModel extends Model
{
    use getEasyQuery;

    static array $get_easy_query_accepted_select = ["id", "name", "field_supp", "field_supp3"];

    static array $get_easy_query_accepted_filters = ["id", "name", "field_supp", "another_field"];

    static array $get_easy_query_accepted_relation_filters = [
        "relation1.id" => "relation1_table.id",
        "relation1.subrelation.name" => "subrelation_table.name"
    ];

    static array $get_easy_query_accepted_with = [
        "relation1",
        "relation1.subrelation",
        "relation2",
    ];

    static array $get_easy_query_accepted_order_by = [ // optionnal, it gonna use the $get_easy_query_accepted_select if not define
        "name",
        "field_supp"
    ]
}

You should define properties inside your model to limit which parameters can be filtered, selected, with closure applied.

Usage

You can get a EloquentQuery with filters, with closure, selected columns defined and sorted easily by passing a structured array as parameters like this

$query = MyModel::getEasyQuery([
    "select" => [
        "id",
        "name",
        "field_supp",
        "field_supp2"
    ],
    "with" => [
        "relation1",
        "relation1.subrelation2",
        "relation2"
    ]
    "filters" => [
        [
            "field"=> "field_supp3",
            "type"=> "LIKE", 
            "value"=> "my_value%"
        ],[
            "field"=> "relation1.field_1",
            "type"=> "IS NULL", 
            "or" => [
                [
                    "field"=> "relation1.field_1",
                    "type"=> ">", 
                    "value"=> 100
                ]
            ]
        ]
    ], 
    "order_by" => [
        ["field"=>"name", "dir" => "asc"],
        ["field"=>"field_supp"]
    ]

])

Structure of the parameters

Select

Accepted_select and select array passed as parameters should be provided as an array, it indicates which of the field of the current model can be requested and will be requested

Filters

The filters parameters should be provided as an array of array. In the example provided in usage part, we gonna have a where close looking like this :

WHERE field_supp3 LIKE 'my_value%' AND (relation1_table_name.field_1 IS NULL OR (relation1_table_name.field_1 > 100 ))

The accepted filters are provided in 2 different properties :

  • For the fields of the current model : $get_easy_query_accepted_filters provided as a simple array
  • For the fields of relation : $get_easy_query_accepted_relation_filters provided as an associative array, where the key is the path to the field throught the relations and the value is "table_name.field_name"

With

Accepted_with and select array passed as parameters should be provided as an array, it indicates which of the field of the current model can be requested and will be requested

Other Methods

Apply the select statement to the query (passed by reference)

MyModel::addSelectToQuery($query, $requested_selects) // Return the $query with the select statement applied (filtered using accepted_select property)

Apply the filters (where close) to the query (passed by reference)

MyModel::addFilterToQuery($query, $requested_filters) // Return the $query with the where statement applied (filtered using accepted_filters and accepted_relation_filters properties)

Apply the with closure (laravel with) to the query (passed by reference)

MyModel::addWithToQuery($query, $requested_with) // Return the $query with the laravel with method applied  applied (filtered using accepted_with property)

Apply the order by close to the query (passed by reference)

MyModel::addOrderByToQuery($query, $requested_order_by) // Return the $query with the order by statement applied (filtered using accepted_order_by property)

theoluirard/laravel-get-easy-query 适用场景与选型建议

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

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

围绕 theoluirard/laravel-get-easy-query 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

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