vskut / laravel5-model-searchable
Searchable scope trait for models in laravel 5
dev-master
2019-05-23 22:45 UTC
Requires
- php: >=7.0
This package is auto-updated.
Last update: 2024-12-24 11:40:48 UTC
README
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).