Package Data | |
---|---|
Maintainer Username: | kevinpijning |
Maintainer Contact: | kevin@pijning.nl (Kevin Pijning) |
Package Create Date: | 2017-05-04 |
Package Last Update: | 2017-06-28 |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-11-23 03:16:44 |
Package Statistics | |
---|---|
Total Downloads: | 1,316 |
Monthly Downloads: | 0 |
Daily Downloads: | 0 |
Total Stars: | 2 |
Total Watchers: | 2 |
Total Forks: | 0 |
Total Open Issues: | 0 |
This package let you easily search through models by a Searchable trait.
Pull this package in through Composer
{
"require": {
"kevinpijning/laravel-searchable": "dev-master"
}
}
$ composer update
Add the package to your application service providers in config/app.php
'providers' => [
App\Providers\RouteServiceProvider::class,
/*
* Third Party Service Providers...
*/
KevinPijning\LaravelSearchable\LaravelSearchableServiceProvider::class,
],
Publish the view:
php artisan vendor:publish
Use Searchable trait inside your Eloquent model(s). Define $searchable array (see example code below).
use KevinPijning\LaravelSearchable\Searchable;
class User extends Model implements AuthenticatableContract, CanResetPasswordContract
{
use Authenticatable, CanResetPassword, Searchable;
...
public $searchable = ['id',
'name',
'email',
'created_at',
'updated_at'];
...
}
Searchable trait adds Searchable scope to the models so you can use it with paginate.
There is one blade extension for you to use @searchableform
@searchableform
This will include a search form to your page.
Route::get('users', ['as' => 'users.index', 'uses' => 'HomeController@index']);
use App\User;
public function index()
{
$users = User::searchable()->paginate(10);
return view('user.index')->withUsers($users);
}
Pagination included
@searchableform
@foreach($users as $user)
{{ $user->name }}
@endforeach
{!! $users->appends(\Request::except('page'))->render() !!}