定制 waxwink/search-repository 二次开发

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

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

waxwink/search-repository

Composer 安装命令:

composer require waxwink/search-repository

包简介

An abstraction repository class for laravel which handles the filtering and searching through a table

README 文档

README

Instruction

create a specific repository for your model (e.g User) and extend the SearchRepository. In your class you should define your filterable and searchable attributes and you are ready to go.

use Waxwink\SearchRepository\SearchRepository;

class UserSearchRepository extends SearchRepository
{

    protected $searchable_attributes = [
        'name',
        'last_name',
        'cellphone',
    ];
    
    protected $filterable_attributes = [
        'birth_date',
        'gender',
        'name',
        'last_name',
        'cellphone',
        'email',
        'created_at'
    ];

    public function __construct()
    {
        $this->query = App\User::query();
    }
}

After creating the search repository class it can be used in your controller as follows while using the SearchTrait:

use Waxwink\SearchRepository\Concerns\SearchTrait;
use Illuminate\Http\Request;

class UserController {
    use SearchTrait;
    
    public function index(Request $request, UserSearchRepository $userSearchRepository)
    {
        $users = $this->filterAndSearch($request, $userSearchRepository)->paginate();
        
        // ...
    }
}

Request Body

The request body should contain the fields that are going to be filtered like the following:

{
    "gender":["m"],
    "created_at":"2019-01-01",
    "birth_date":["1999-01-01", ">"],
    "name":["joe", "like"]
}

Search Param

Search param should contain the searching key words like:

app/users?search=jack

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-12-01

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固