承接 san4io/eloquent-filter 相关项目开发

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

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

san4io/eloquent-filter

Composer 安装命令:

composer require san4io/eloquent-filter

包简介

Laravel Eloquent Filter Package

README 文档

README

Build Status Scrutinizer Code Quality Code Coverage

Package to filter your Eloquent model simply and elegantly.

Requirements

  • "php": ">=7.1",
  • "illuminate/support": "5.*",
  • "illuminate/database": "5.*"

Installation

composer require san4io/eloquent-filter

Usage

Model

Add Filterable trait to your eloquent model.

Create $filterable property with mappings corresponding to how model attributes should be filtered.

class Event extends Model
{
    use Filterable;
    
    protected $fillable = [
        'country_id',
        'title',
    ];
    
    protected $filterable = [
        'country_id' => WhereFilter::class,
        'title' => LikeFilter::class,
        'created_at' => BetweenFilter::class
    ];
}

Controller

Just pass Request params to filter as array.

public function index(Request $request): JsonResponse
{
    $events = Event::filter($request->all())->paginate(); // or get(), first() or whatever
    
    return response()->json($events);
}

Request examples

http://localhost/api/v1/events?country_id=101&title=Sport

http://localhost/api/v1/events?country_id[]=101&country_id[]=102&title=Sport

http://localhost/api/v1/events?created_at[from]=2017-07-11&created_at[till]=2017-08-11&title=Sport

Filters

The package was build with mind that it should be easily extensible, that's why if you need some custom filters, you can extend AbstractFilter and add necessary mapping to the model.

By default where are 3 filter types:

  • WhereFilter
  • LikeFilter
  • BetweenFilter

WhereFilter

Accepts integer or array of integers

LikeFilter

Accepts string

BetweenFilter

Accepts array with keys ['from'] and ['till']

Road map

  • Tests
  • Filtering Relations

Contribution

Any contributions welcome!

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-10-29

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固