PHPackages                             andrewboy/search-box - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Admin Panels](/categories/admin)
4. /
5. andrewboy/search-box

ActiveLibrary[Admin Panels](/categories/admin)

andrewboy/search-box
====================

Laravel package for admin search box.

2288JavaScript

Since Jun 17Pushed 9y ago1 watchersCompare

[ Source](https://github.com/andrewboy/SearchBox)[ Packagist](https://packagist.org/packages/andrewboy/search-box)[ RSS](/packages/andrewboy-search-box/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

SearchBox
=========

[](#searchbox)

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!

Installation
------------

[](#installation)

add bundle to composer:

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

```

run composer:

```
composer install / update
```

add service provider to the providers list:

```
'Andrewboy\SearchBox\SearchBoxServiceProvider'

```

publish view, langs and public parts:

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

Set up javascript plugin
------------------------

[](#set-up-javascript-plugin)

add javascript plugin to the site

```

```

or the minified version

```

```

add plugin to your javascript file

```
$('.searchbox').searchBox();
```

\##Javascript events

```
$('.searchbox').searchBox({
    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

[](#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

[](#2-you-can-pass-the-parameters-through-the-plugin)

```
$('.searchbox').searchBox({
    params: {{ searchParams }}
});
```

Set up Model
------------

[](#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)
{
    #BANNER_PLACE_ID
    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']);
                break;

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

        unset($params['banner_place_id']);
    }

    #HAS_ATTACHMENT
    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]));
                break;

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

        unset($params['has_attachment']);
    }

    return $params;
}
```

### Use Models' realtions with the fast and easy way

[](#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

```
[
    [relation_method_name],
    [attribute_name_which_you_want_to_use_in_dropdown]
]
```

Set up the controller
---------------------

[](#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))
    ->with(
        'searchParams',
        Banner::getSearchSet(
            route("banners.index"),
            $extended
        )
    )
```

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
------------

[](#set-language)

default language set is hu, en

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

Set view
--------

[](#set-view)

to insert the view

```
@include('search-box::searchBox')
```

Built in filters
----------------

[](#built-in-filters)

### Integer

[](#integer)

Operators: equals (=), not equals (!=), greater than or equal (&gt;=), less than or equal (&lt;=), (&gt;&lt;),

### Date

[](#date)

Operators: equals (=), greater than or equal (&gt;=), less than or equal (&lt;=), not equal (&gt;&lt;)

### String

[](#string)

Operators: contains (), not contains (!)

### Boolean

[](#boolean)

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

### List

[](#list)

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

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

\##Options

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

\###Caching

```
'is_caching'    =>  true
```

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/1fffd03f6394ab7501672bb08668811da515facc3e160cfd1d433fbbd53a352c?d=identicon)[andrewboy](/maintainers/andrewboy)

### Embed Badge

![Health badge](/badges/andrewboy-search-box/health.svg)

```
[![Health](https://phpackages.com/badges/andrewboy-search-box/health.svg)](https://phpackages.com/packages/andrewboy-search-box)
```

###  Alternatives

[jeroennoten/laravel-adminlte

Easy AdminLTE integration with Laravel

4.0k4.8M43](/packages/jeroennoten-laravel-adminlte)[dmstr/yii2-adminlte-asset

AdminLTE backend theme asset bundle for Yii 2.0 Framework

1.1k1.8M67](/packages/dmstr-yii2-adminlte-asset)[dwij/laraadmin

LaraAdmin is a Open source Laravel Admin Panel / CMS which can be used as Admin Backend, Data Management Tool or CRM boilerplate for Laravel with features like CRUD Generation, Module Manager, Media, Menus, Backups and much more

1.6k68.7k](/packages/dwij-laraadmin)[filament/spatie-laravel-media-library-plugin

Filament support for `spatie/laravel-medialibrary`.

1764.8M125](/packages/filament-spatie-laravel-media-library-plugin)[bezhansalleh/filament-exceptions

A Simple &amp; Beautiful Pluggable Exception Viewer for FilamentPHP's Admin Panel

193195.9k13](/packages/bezhansalleh-filament-exceptions)[filament/infolists

Easily add beautiful read-only infolists to any Livewire component.

1220.8M36](/packages/filament-infolists)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
