LaravelPackages.net
Acme Inc.
Toggle sidebar
jhacobs/laravel-searchable

Search through models

5
1
v1.0.0
About jhacobs/laravel-searchable

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

Laravel searchable

Packagist Version GitHub PHP Workflow

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

License

MIT

Comments