The Vhnh Search package provides a simple search for Eloquent.
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;
// ...
}
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']);
The Vhnh Search package is open-sourced software licensed under the MIT license.