bigdropinc / laravel-simple-search
Laravel package for search.
Installs: 1 882
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 2
Forks: 1
Open Issues: 0
Requires
- php: >=7.0
- illuminate/console: >=5.6
This package is not auto-updated.
Last update: 2024-11-12 16:08:50 UTC
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