This package is not installable via Composer 1.x, please make sure you upgrade to Composer 2+. Read more about our Composer 1.x deprecation policy.
There is no license information available for the latest version (dev-master) of this package.

Laravel package for admin search box.

Installs: 288

Dependents: 0

Suggesters: 0

Security: 0

Stars: 2

Watchers: 1

Forks: 0

Open Issues: 0


dev-master 2016-06-17 12:30 UTC

This package is not auto-updated.

Last update: 2021-07-16 06:35:13 UTC


This is a Laravel 5 package, that creates a searcbox for admin pages that uses Twitter Bootstrap.

It's under development, not recommended for production use!


add bundle to composer:

"andrewboy/search-box": "dev-master"

run composer:

composer install / update

add service provider to the providers list:


publish view, langs and public parts:

php artisan vendor:publish --provider="Andrewboy\SearchBox\SearchBoxServiceProvider"

Set up javascript plugin

add javascript plugin to the site

<script src="{{asset('vendor/search-box/js/jquery.searchBox.js')}}"></script>

or the minified version

<script src="{{asset('vendor/search-box/js/jquery.searchBox.min.js')}}"></script>

add plugin to your javascript file


##Javascript events

    itemBeforeInit(){},     //before search item init
    itemAfterInit(item){}   //after search item init

You have two choice to pass the search params

1. Just create the 'searchParams' php variable in the controller and pass it to the view

Explained in the controller section

2. You can pass the parameters through the plugin

    params: {{ searchParams }}

Set up Model

add the trait to your models that you want to search

use \Andrewboy\SearchBox\Traits\SearchTrait;

class Banner extends Eloquent

    use SearchTrait;

in the model set the attributes like:

protected static $searchParams = [
    'id' => [
        'type' => 'integer'
    'name' => [
        'type' => 'string'
    'url' => [
        'type' => 'string'
    'is_active' => [
        'type' => 'boolean'
    'has_attachment' => [
        'type' => 'boolean'
    'group_id'    =>  [
        'type'  =>  'list',
        'relation'  =>  ['groups', 'name']
    'group_id'    =>  [
        'type'  =>  'list',
        'values'  =>  [
            1 => 'name1',
            2 => 'name2'
    'group_id'    =>  [
        'type'  =>  'string',
        'relation'  =>  ['groups', 'name']  //search string through relation
    'created_at' => [
        'type' => 'date'

in the model, extend the search for special cases

protected function extendSearch($query, array $params)
    if (isset($params['banner_place_id']) && self::isValidSearchParam($params['banner_place_id'])) {
        switch ($params['banner_place_id']['operator']) {
            case '=':
                $query->whereIn('banner_place_id', $params['banner_place_id']['values']);

            case '!=':
                $query->whereNotIn('banner_place_id', $params['banner_place_id']['values']);


    if (isset($params['has_attachment']) && self::isValidSearchParam($params['has_attachment'])) {
        switch ($params['has_attachment']['operator']) {
            case '=':
                $query->has('attachment', 'LIKE', intval($params['has_attachment']['values'][0]));

            case '!=':
                $query->has('attachment', 'NOT LIKE', intval($params['has_attachment']['values'][0]));


    return $params;

Use Models' realtions with the fast and easy way

when you want to reach the models' relations, the you have to define like this

    protected static $searchParams = [
        'group_id'    =>  [
            'type'  =>  'list',
            'relation'  =>  ['groups', 'name']

where the type is set to 'list'

the relation is set by


Set up the controller

in the controller, pass the search params:

$extended = []; //you don't have to use it, if it's empty

return View::make('banners.index', array('banners' => $banners))

in the controller you can extend the previosly filled search settings:

$extended = [
    'banner_place_id'    =>  [
        'type'      =>  'list',
        'values'    =>  Banner::$bannerPlaces

in the controller, you can use it to search

$banners = Banner::search(Input::all());

Set language

default language set is hu, en

you can extend the language in 'resources/lang/vendor/search-box'

Set view

to insert the view


Built in filters


Operators: equals (=), not equals (!=), greater than or equal (>=), less than or equal (<=), (><),


Operators: equals (=), greater than or equal (>=), less than or equal (<=), not equal (><)


Operators: contains (), not contains (!)


Operators: true (!!1), false (!!0)


Operators: equals (=), not equals (!=)

write down how to publish the parts of the code etc.


The "getSearchSet" method 3rd parameter is the options parameter. The type of the parameter is array.


'is_caching'    =>  true