定制 jti/laravelfilter 二次开发

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

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

jti/laravelfilter

最新稳定版本:0.1

Composer 安装命令:

composer require jti/laravelfilter

包简介

Filter scope for Laravel

README 文档

README

Latest Version on Packagist Total Downloads Build Status StyleCI

This is where your description should go. Take a look at contributing.md to see a to do list.

Installation

Via Composer

composer require jti/laravelfilter

Usage

  1. Use trait with scope in your Model
<?php

namespace App\Models;

use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    use Filterable;
}


trait Filterable
{
    /**
     * @param Builder $builder
     * @param LaravelFilter $filter
     */
    public function scopeFilter(Builder $builder, LaravelFilter $filter): void
    {
        $filter->apply($builder);
    }
}
  1. Create your Filter class
class UserFilter extends \JTI\LaravelFilter\LaravelFilter
{

    protected function initBuilder(\Illuminate\Database\Eloquent\Builder $builder): \Illuminate\Database\Eloquent\Builder
    {
        return $this->builder = $builder; // your model builder
    }

    // function name equal key name from array of params
    public function email($email = '')
    {
        if ($email) {
            $this->builder->where('email', '=', $name);
        }
    }
}
}
  1. Use filter in controller for example
class BuilderController extends Controller
{
    public function index()
    {
        $filter = new UserFilter(['email' => 'example@gmail.com']);
        $users = \App\Models\User::query()->filter($filter)->get();
        
        return view('users', compact('users'));
    }

}

Change log

Please see the changelog for more information on what has changed recently.

Testing

composer test

Contributing

Please see contributing.md for details and a todolist.

Security

If you discover any security related issues, please email yuriy.kernytskyi@jointoit.com instead of using the issue tracker.

Credits

License

MIT. Please see the license file for more information.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-01-14