Looking to hire Laravel developers? Try LaraJobs

laravel-searchable maintained by jhacobs

Description
Search through models
Author
Last update
2021/09/19 03:30 (dev-main)
License
Links
Downloads
5

Comments
comments powered by Disqus

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