Skip to content

vhnh/search

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

VHNH

vhnh/search

The Vhnh Search package provides a simple search for Eloquent.

tests

Setup

To make a model searchable it should implement the Vhnh\Search\Contracts\Searchable interface and use the Vhnh\Search\Searchable trait.

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Vhnh\Search\Contracts\Searchable as SearchableContract;
use Vhnh\Search\Searchable;

class Book extends Model implements SearchableContract
{
    use Searchable;

    // ...
}

Usage

The Vhnh\Search\Contracts\Searchable::search() method simply follows the needle in haystack principle and accepts the search term as its first paramter and an array of attributes as the second parameter.

Book::search('tolkien', ['author']);

License

The Vhnh Search package is open-sourced software licensed under the MIT license.