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
其他信息
- 授权协议: MIT
- 更新时间: 2019-12-01