bigdropinc/laravel-simple-search
Composer 安装命令:
composer require bigdropinc/laravel-simple-search
包简介
Laravel package for search.
README 文档
README
#Laravel Simple Search
##Requirements
Make sure all dependencies have been installed before moving on:
- PHP >= 7.0
Pull the package via Composer:
The preferred way to install this extension is through composer.
Either run
composer require bigdropinc/laravel-simple-search "1.0.0"
or add
"bigdropinc/laravel-simple-search": "1.0.0"
to the require section of your composer.json file.
Usage
Once the extension is installed, simply use it in your code by:
UserSearch::apply(User:class, request()->all());
Filters
All attributes that should be used described in property fillable
protected $fillable = [ 'id', 'first_name', 'last_name', ];
By default for each attribute applied condition =
Example:
protected $fillable = [ 'id', 'name' => 'first_name', //alias: name - search attr, first_name - db attr 'last_name', ];
Equivalent
User::where('first_name', $firstNameValue) ->where('last_name', $lastNameValue) ->where('id', $userIdValue)
Сustom filters
pulic function id($value) { $this->query->where('id', '>', $value); }
Cast
Used default Laravel attribute casting. By default use string cast
protected $cast = [ 'id' => 'integer', ];
Sort
Default sort
protected $defaultSort = 'first_name';
Ascending order by first_name: sort=first_name
Descending order by first_name: sort=-first_name | hyphen (-) in the start
统计信息
- 总下载量: 2.11k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2019-05-15