DownloadLaravel Global Search [WIP]
Laravel Global Search
Installation
composer require php-junior/laravel-global-search
Laravel 5.5 uses Package Auto-Discovery, so doesn't require you to manually add the ServiceProvider.
If you don't use auto-discovery, add the ServiceProvider to the providers array in config/app.php
PhpJunior\LaravelGlobalSearch\LaravelGlobalSearchProvider::class,
php artisan vendor:publish --provider="PhpJunior\LaravelGlobalSearch\LaravelGlobalSearchProvider"
This is the contents of the published config file:
return [
'resources' => [
\App\Models\Auth\User::class
],
'limit' => 10
];
Usage
First <code>PhpJunior\LaravelGlobalSearch\Traits\GlobalSearchable</code> trait to models
use PhpJunior\LaravelGlobalSearch\Traits\GlobalSearchable;
class User extends Authenticatable
{
use GlobalSearchable;
/
* The columns that should be searched.
*
* @var array
*/
protected $search = [
'name', 'email',
];
/
* The columns that should be displayed.
*
* @var array
*/
protected $only = [
'name', 'email'
];
/
* The columns that should be ordered.
*
* @var array
*/
protected $order = [
'name' => 'desc',
'email' => 'asc'
];
// Optional
protected $searchQuery = [
[
'method' => 'where',
'column' => 'email',
'operator' => '=',
'value' => 'usern@user.com'
],
[
'method' => 'whereBetween',
'column' => 'votes',
'value' => [1, 100]
]
];
/
* @var string
*/
protected $searchIndex = 'users-index';
}
Search LaravelGlobalSearch::search($text)
Credits
License
The MIT License (MIT). Please see License File for more information.
|