PHP code example of php-junior / laravel-global-search

1. Go to this page and download the library: Download php-junior/laravel-global-search library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

php-junior / laravel-global-search example snippets


composer 

PhpJunior\LaravelGlobalSearch\LaravelGlobalSearchProvider::class,
 
php artisan vendor:publish --provider="PhpJunior\LaravelGlobalSearch\LaravelGlobalSearchProvider"

return [
    'resources' => [
        \App\Models\Auth\User::class
    ],
    'limit' => 10
];

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' => '[email protected]'
        ],
        [
            'method' => 'whereBetween',
            'column' => 'votes',
            'value' => [1, 100]
        ]
    ];

    /**
     * @var string
     */
    protected $searchIndex = 'users-index';
}

LaravelGlobalSearch::search($text)