#Laravel Simple Search
##Requirements
Make sure all dependencies have been installed before moving on:
- PHP >= 7.0
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.
Once the extension is installed, simply use it in your code by:
UserSearch::apply(User:class, request()->all());
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)
pulic function id($value) {
$this->query->where('id', '>', $value);
}
Used default Laravel attribute casting. By default use string
cast
protected $cast = [
'id' => 'integer',
];
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