2017 © Pedro Peláez
 

library laravel-searchable

Easy table searching for Laravel

image

kevinpijning/laravel-searchable

Easy table searching for Laravel

  • Thursday, May 4, 2017
  • by kevinpijning
  • Repository
  • 1 Watchers
  • 0 Stars
  • 278 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 7 % Grown

The README.md

Searchable Laravel (5.*)

This package let you easily search through models by a Searchable trait., (*1)

Setup

Composer

Pull this package in through Composer, (*2)

{
    "require": {
        "kevinpijning/laravel-searchable": "dev-master"
    }
}

$ composer update, (*3)

Add the package to your application service providers in config/app.php, (*4)

'providers' => [

    App\Providers\RouteServiceProvider::class,

    /*
     * Third Party Service Providers...
     */
     KevinPijning\LaravelSearchable\LaravelSearchableServiceProvider::class,
],

Publish the view:, (*5)

php artisan vendor:publish

Usage

Use Searchable trait inside your Eloquent model(s). Define $searchable array (see example code below)., (*6)

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., (*7)

Blade extension

There is one blade extension for you to use @searchableform, (*8)

@searchableform, (*9)

This will include a search form to your page., (*10)

Full example

Routes

Route::get('users', ['as' => 'users.index', 'uses' => 'HomeController@index']);

Controller

use App\User;

public function index()
{
    $users = User::searchable()->paginate(10);

    return view('user.index')->withUsers($users);
}

View

Pagination included, (*11)

@searchableform

@foreach($users as $user)
    {{ $user->name }}
@endforeach

{!! $users->appends(\Request::except('page'))->render() !!}

The Versions

04/05 2017

dev-master

9999999-dev

Easy table searching for Laravel

  Sources   Download

MIT

The Requires

 

by Kevin Pijning

laravel search searchable laravel-searchable

04/05 2017

v1.0

1.0.0.0

Easy table searching for Laravel

  Sources   Download

MIT

The Requires

 

by Kevin Pijning

laravel search searchable laravel-searchable