jhacobs / laravel-searchable
Search through models
v1.0.0
2021-09-19 01:21 UTC
Requires
- php: ^7.4|^8.0
- illuminate/database: ^7.0|^8.0
- illuminate/support: ^7.0|^8.0
Requires (Dev)
- orchestra/testbench: ^6.21
- phpunit/phpunit: ^9.5
README
Search through models with laravel searchable
Installation
You can install the package via composer
composer require jhacobs/laravel-searchable
Usage/Examples
Prepare your models
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' ]; }
Searching models
You can search through your models by using the search scope.
User::search('Henk') ->get();
Running Tests
To run tests, run the following command
composer test