htetoozin/eloquent-filter 问题修复 & 功能扩展

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

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

htetoozin/eloquent-filter

最新稳定版本:v1.0.0

Composer 安装命令:

composer require htetoozin/eloquent-filter

包简介

Laravel Eloquent Filter

README 文档

README

📥 Installation

You can install this package via composer using this command:


composer require htetoozin/eloquent-filter

Usage

Run php artisan make:filter {name} this file generate and stored at the location of app/Filters/. eg..

php artisan make:filter UserFilter

will generate such file content of UserFilter.php

Important

Array value and the method name must be the same; otherwise, the filter will not work.

<?php

namespace App\Filters;

use HtetOoZin\EloquentFilter\Filters\Filter;

class UserFilter extends Filter
{
    /**
     * Register filter properties
     */
    protected $filters = ['keyword'];


    /**
     * Filter by keyword.
     */
    public function keyword($value)
    {
        return $this->builder->where('name', 'like', "%{$value}%");
    }
}

Add local query scope in related model.

<?php

class User extends Model
{
    public function scopeFilter($query, $filter)
    {
        $filter->apply($query);
    }
}

Import UserFilter class to related controller.

<?php

use App\Filters\UserFilter;

class UserController extends Controller
{
    public function index(UserFilter $filter)
    {
        return User::filter($filter)->get();
    }
}

📜 License

The MIT License (MIT). Please see License File for more information.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-12-22