定制 sufian/laravel-query-filter 二次开发

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

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

sufian/laravel-query-filter

最新稳定版本:v0.1.0

Composer 安装命令:

composer require sufian/laravel-query-filter

包简介

A Laravel package to filter queries based on model properties.

README 文档

README

A Laravel package to filter Eloquent queries based on model properties.

Installation

Step 1: Install the Package

You can install the package via Composer:

composer require sufian/laravel-query-filter

Usage

Step 1: Use the Filterable Trait

Add the Filterable trait to the Eloquent models you want to filter:

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Sufian\QueryFilter\Filterable;

class User extends Model
{
    use Filterable;
}

Step 2: Create Filter Classes

To generate a new filter class, use the make:filter Artisan command followed by the name of the class you want to create. For example, to create a filter class for the User model, run:

php artisan make:filter YourModel Name

Example:

php artisan make:filter User

OR Create filter classes in the App\Filters namespace for each model manually:

Example UserFilter Class

namespace App\Filters;

use Sufian\QueryFilter\BaseFilter;
use Illuminate\Database\Eloquent\Builder;

class UserFilter extends BaseFilter
{
    protected $filters = ['name', 'email'];

    public function name(Builder $query, $value)
    {
        $query->where('name', 'like', '%' . $value . '%');
    }

    public function email(Builder $query, $value)
    {
        $query->where('email', 'like', '%' . $value . '%');
    }
}

Step 3: Use the Filter in Controllers

You can now use the filter method in your controllers:

UserController

namespace App\Http\Controllers;

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

class UserController extends Controller
{
    public function index(Request $request)
    {
        $users = User::filter()->get();
        return response()->json($users);
    }
}

Contributing

Thank you for considering contributing to the Laravel Query Filter package! Please read the contribution guidelines for details on how to contribute.

Security Vulnerabilities

If you discover a security vulnerability within this Laravel Query Filter package, please send an e-mail to sufian at rubel.nstu27@gmail.com. All security vulnerabilities will be promptly addressed.

License

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-06-08