/laravel5-model-searchable

Search scope for laravel models

Primary LanguagePHP

Laravel 5 Model Trait Searchable

Provides the searching trait for Laravel Eloquent models.

This package has been developed by Markus Lind. Visit me at vskut.ru.

Install

Via composer:

$ composer require vskut/laravel5-model-searchable

Usage

Model

use vskut\laravel5ModelSearchable\Searchable;

class User extends Model
{
    use Searchable;

}

Controller

class UserController
{

    public function index()
    {
        $user = User::searchable(request()->get('search'), ['id', 'email', 'username'])
            ->get();

        return view('user.index', compact('user'));
    }
}

View

<form action="{{ route('user.index') }}" method="get">
    <input type="text" name="search" value="{{ request()->get('search') }}">
    <button type="submit">Search</button>
</form>

Credits

License

The MIT License (MIT).