jhacobs/laravel-searchable

Search through models

Installs: 5

Dependents: 0

Suggesters: 0

Security: 0

Stars: 1

Watchers: 2

Forks: 0

Open Issues: 0

pkg:composer/jhacobs/laravel-searchable

v1.0.0 2021-09-19 01:21 UTC

This package is auto-updated.

Last update: 2025-09-19 10:42:17 UTC


README

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