jhacobs/laravel-searchable is a Laravel package for search through models.
It currently has 1 GitHub stars and 5 downloads on Packagist (latest version v1.0.0).
Install it with composer require jhacobs/laravel-searchable.
Discover more Laravel packages by jhacobs
or browse all Laravel packages to compare alternatives.
Last updated
Search through models with laravel searchable
You can install the package via composer
composer require jhacobs/laravel-searchable
Add the Searchable trait to the model you want to search through.
namespace App\Models\User;
use Illuminate\Database\Eloquent\Model;
use Jhacobs\Searchable\Searchable;
class User extends Model
{
use Searchable;
}
Then add the fields you want to be searchable to the $searchables property.
namespace App\Models\User;
use Illuminate\Database\Eloquent\Model;
use Jhacobs\Searchable\Searchable;
class User extends Model
{
use Searchable;
protected $searchables = [
'name',
'email'
];
}
You can search through your models by using the search scope.
User::search('Henk')
->get();
To run tests, run the following command
composer test