PHP Classes

File: README.md

Recommend this page to a friend!
  Classes of Nyi Nyi Lwin  >  Laravel PHP Global Search  >  README.md  >  Download  
File: README.md
Role: Documentation
Content type: text/markdown
Description: Documentation
Class: Laravel PHP Global Search
Provide search capabilities to data objects
Author: By
Last change:
Date: 3 years ago
Size: 2,429 bytes
 

Contents

Class file image Download

Laravel Global Search [WIP]

Laravel Global Search

Latest Stable Version Total Downloads License

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

  • All Contributors

License

The MIT License (MIT). Please see License File for more information.

For more information send a message to info at phpclasses dot org.