PHP Classes

Laravel PHP Global Search: Provide search capabilities to data objects

Recommend this page to a friend!
  Info   Documentation   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 71 All time: 10,265 This week: 455Up
Version License PHP version Categories
laravel-global-searc 1.0.0The PHP License5PHP 5, Databases, Searching, Libraries
Description 

Author

This package can provide search capabilities to data objects.

It provides a trait that can be used by an class of data objects so when information needs to be searched, the trait will access variables of that class to determine how the data object information can be searched.

The data object class variables need to inform the list of fields that can be used to search information, sort results, as well parameters to compose search queries.

Innovation Award
PHP Programming Innovation award nominee
January 2019
Number 4
Laravel is a very popular PHP framework that supports modern design patterns, PHP standard specifications and more recent PHP language features.

This package uses Laravel to implement a global search interface to any class using a trait to simplify searching for data objects information stored in a database.

Manuel Lemos
Picture of Nyi Nyi Lwin
  Performance   Level  
Name: Nyi Nyi Lwin <contact>
Classes: 12 packages by
Country: Myanmar Myanmar
Age: 32
All time rank: 26565 in Myanmar Myanmar
Week rank: 46 Up1 in Myanmar Myanmar Up
Innovation award
Innovation award
Nominee: 7x

Winner: 4x

Documentation

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.


  Files folder image Files (8)  
File Role Description
Files folder imageconfig (1 file)
Files folder imagesrc (1 file, 3 directories)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files (8)  /  config  
File Role Description
  Plain text file laravel-global-search.php Class Class source

  Files folder image Files (8)  /  src  
File Role Description
Files folder imageFacades (1 file)
Files folder imageServices (1 file)
Files folder imageTraits (1 file)
  Plain text file LaravelGlobalSearchProvider.php Class Class source

  Files folder image Files (8)  /  src  /  Facades  
File Role Description
  Plain text file LaravelGlobalSearch.php Class Class source

  Files folder image Files (8)  /  src  /  Services  
File Role Description
  Plain text file LaravelGlobalSearch.php Class Class source

  Files folder image Files (8)  /  src  /  Traits  
File Role Description
  Plain text file GlobalSearchable.php Class Class source

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:71
This week:0
All time:10,265
This week:455Up