PHPackages                             tasdan/column-searchable - 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. [Search &amp; Filtering](/categories/search)
4. /
5. tasdan/column-searchable

ActivePackage[Search &amp; Filtering](/categories/search)

tasdan/column-searchable
========================

Package for searching by columns in Laravel

0.6(3y ago)02.9k↓50%MITPHPPHP ^7.0|^8.0

Since Nov 25Pushed 3y ago1 watchersCompare

[ Source](https://github.com/tasdan/column-searchable)[ Packagist](https://packagist.org/packages/tasdan/column-searchable)[ RSS](/packages/tasdan-column-searchable/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (2)Versions (7)Used By (0)

Searching in model's columns for Laravel 5.5-8
==============================================

[](#searching-in-models-columns-for-laravel-55-8)

A package for searching in your eloquent model's column, with relations in Laravel.

[![Total Downloads](https://camo.githubusercontent.com/aae566b1bb877a16a61fa7a9e61f871f25ee8235bbb70dfc91c83f89960aadae/68747470733a2f2f706f7365722e707567782e6f72672f74617364616e2f636f6c756d6e2d73656172636861626c652f646f776e6c6f616473)](//packagist.org/packages/tasdan/column-searchable)[![Latest Stable Version](https://camo.githubusercontent.com/018bc566af7adf2692c69a5971d4358a4bd58105cf1ffb237f36faf4b8e85cb4/68747470733a2f2f706f7365722e707567782e6f72672f74617364616e2f636f6c756d6e2d73656172636861626c652f76)](//packagist.org/packages/tasdan/column-searchable)[![Latest Unstable Version](https://camo.githubusercontent.com/cb11bd20188e8883ecc4ce4ea47dd07a50140fb8657b5a8ea07ef7ddea5a553a/68747470733a2f2f706f7365722e707567782e6f72672f74617364616e2f636f6c756d6e2d73656172636861626c652f762f756e737461626c65)](//packagist.org/packages/tasdan/column-searchable)[![License](https://camo.githubusercontent.com/f41f4df087c57d53729d76a5a966540978265c0e11ebb0759c6e6e1e74d26f7e/68747470733a2f2f706f7365722e707567782e6f72672f74617364616e2f636f6c756d6e2d73656172636861626c652f6c6963656e7365)](//packagist.org/packages/tasdan/column-searchable)

#### Table of contents

[](#table-of-contents)

- [Installation](#installation)
    - [Composer](#composer)
    - [Service provider](#service-provider)
    - [Configuration](#configuration)
- [Usage](#usage)
- [Configurations](#configurations)
    - [Config examples](#config-examples)
- [Blade Extension](#blade-extension)
    - [Searchable input field](#searchable-input-field)
    - [Searchable script](#searchable-script)
- [Pagination](#pagination)
- [Full example](#full-example)
- [Library Note](#library-note)
- [License](#license)

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

[](#installation)

### Composer

[](#composer)

Install the package with composer require command:

```
composer require "tasdan/column-searchable"
```

### Service provider

[](#service-provider)

Next, add the new provider to the `providers` array in `config/app.php` (only when Laravel &lt; 5.5):

```
'providers' => [
    // ...
    /**
     * Third Party Service Providers...
     */
    Tasdan\ColumnSearchable\ColumnSearchableServiceProvider::class,
    // ...
],
```

### Configuration

[](#configuration)

You can publish the configuration file with the following command:

```
php artisan vendor:publish --provider="Tasdan\ColumnSearchable\ColumnSearchableServiceProvider" --tag="config"
```

After that, you can change the default configurations in `config/columnsearchable.php` file.

Usage
-----

[](#usage)

To use searchable scope, you have to add **Searchable** trait inside the *Eloquent* models. **Searchable** trait adds Searchable scope to the models. Then define `$searchable` array in model's definition (check the configuration section to more info):

```
use Tasdan\ColumnSearchable\Searchable;

class User extends Model implements AuthenticatableContract, CanResetPasswordContract
{
    use Authenticatable, CanResetPassword, Searchable;
    // ...

    public $searchable = [
        'search_field_name_1' => [
            'relation' => 'relation_table_name',
            'columns' => 'column_name',
            'type' => 'string/int'
        ],
        'search_field_name_2' => [
            'relation' => 'relation_table_name',
            'columns' => 'column_name',
            'type' => 'string/int'
        ],
    // ...
}
```

After you defined the `$searchable` array, you can use `searchable` scope in your controllers:

```
 $users = User::searchable()->paginate(15);
```

You can execute a search function when the requested URL has one of the defined `$searchable` key, see this example:

```
https://yourdomain.com/users?search_field_name_1=test%20user
```

> **Note**: the parameter values in URL are URL-encoded.

Configurations
--------------

[](#configurations)

You can configure search field as much as you want, with the following pattern:

- **search\_field\_name\_1**: the name of this search field, can be anything, or the column name where you want to search
- **relation**: the related table name, can be omitted, or the current model's table name
- **columns**: the column name(s) where you want to search, use an array, when you want to search in multiple columns
- **type**: the column type, must be string or int (if string, the query be like 'LIKE %xyz%'), can be omitted

### Config examples

[](#config-examples)

```
 public $searchable = [
        //search in name column in current table with string type
        'name',

        //search in selected columns with OR relation in current table with string type
        'address' => [
            'columns' => [
                'country',
                'city',
                'zip_code',
                'street'
            ]
        ],

        //search in activation_code column in current table with string type, but the search field name is activation
        'activation' => [
            'columns' => 'activation_code'
        ],

        //search in is_active column in current table with int type
        'is_active' => [
            'type' => 'int'
        ],

        //search in a belongs-to related table's name column, with string type
        'school_name' => [
            'relation' => 'school',
            'columns' => 'name',
            'type' => 'string'
        ],

        //search in a belongs-to related table's city and street column with string type'
        'school_address' => [
            'relation' => 'school',
            'columns' => [
                'city',
                'street'
            ],
            'type' => 'string'
        ],

        //search in a has-many related table's firstname and lastname column with string type
        'student_name' => [
            'relation' => 'students',
            'columns' => [
                'firstname',
                'lastname'
            ],
            'type' => 'string'
        ]
    ];
```

Blade Extension
---------------

[](#blade-extension)

There are two blade extension for you to use searchable functions

#### Searchable input field

[](#searchable-input-field)

In blade files you can use the **@searchablefield()** extension to automatically generated search input form.

```
@searchablefield('field_type', 'search_field_name', 'Title', $selectOptionsArray, ['class' => 'form-control'])
```

> **Note**: the search-input class automatically added to this generated fields, to able to work the **@searchablescript()** extension.

This first parameter (**field\_type**) must be one of the following:

- text
- select

The second parameter is the searchable field name, which is already defined in model's `$searchable` array. The third parameter is the title-placeholder value of the field. The fourth parameter depends on the type parameter:

- if type is text, this is an array with additional form values (optional)
- if type is select, this is an array with select options key-value pairs

The fifth parameter is optional when type is select, and this is an array with additional form values.

Possible examples and usages of this balde extension:

```
@searchablefield('text', 'name', __('fields.name'))
@searchablefield('text', 'location', __('fields.location'), ['class' => 'form-control form-control-sm'])
@searchablefield('select', 'is_active', __('fields.active'), $activeSelectOptions)
@searchablefield('select', 'position', __('fields.position'), ["1" => "POS 1", "2" => "POS 2"] ,['class' => 'form-control'])
```

#### Searchable script

[](#searchable-script)

In blade files you can use the **@searchablescript()** extension to automatically generated search Javascript functions. After this you can call `search()` function to execute a search request.

Example use of **@searchablescript()** extension:

```

    @searchablescript()

// ...

    $("#searchButton").click(function () {
        search();
    });

```

> **Note**: you have to call **@searchablescript()** extension inside script tag, because this extension returns only with JS functions code. In this way, you can use CSP-nonce on this include.

Pagination
----------

[](#pagination)

If you use pagination in blade, you have to update the pagination links, to keep searching parameters in URL when page change.

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

Full example
------------

[](#full-example)

***TODO***

Library Note:
-------------

[](#library-note)

This is my first Laravel package, so maybe there is some problem with that, but I will handle those as soon as possible.

License
-------

[](#license)

This package is free software distributed under the terms of the [MIT license](https://opensource.org/licenses/MIT). Enjoy!

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

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.

###  Release Activity

Cadence

Every ~168 days

Recently: every ~210 days

Total

6

Last Release

1158d ago

PHP version history (2 changes)0.1PHP &gt;=7.2

0.5PHP ^7.0|^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/a1da8dc0ed0cfffa07fc10d5250438d85ff1074af2b33f323b08f4da61e50bae?d=identicon)[tasdan5817](/maintainers/tasdan5817)

---

Top Contributors

[![tasdan5817](https://avatars.githubusercontent.com/u/102207876?v=4)](https://github.com/tasdan5817 "tasdan5817 (13 commits)")

---

Tags

laravelsearchlaravelsearchablesortingcolumn

### Embed Badge

![Health badge](/badges/tasdan-column-searchable/health.svg)

```
[![Health](https://phpackages.com/badges/tasdan-column-searchable/health.svg)](https://phpackages.com/packages/tasdan-column-searchable)
```

###  Alternatives

[kyslik/column-sortable

Package for handling column sorting in Laravel 6.x

6485.6M21](/packages/kyslik-column-sortable)[algolia/scout-extended

Scout Extended extends Laravel Scout adding algolia-specific features

4186.3M6](/packages/algolia-scout-extended)[jeroen-g/explorer

Next-gen Elasticsearch driver for Laravel Scout.

397612.3k](/packages/jeroen-g-explorer)[devnoiseconsulting/laravel-scout-postgres-tsvector

PostgreSQL Full Text Search Driver for Laravel Scout

58110.1k](/packages/devnoiseconsulting-laravel-scout-postgres-tsvector)

PHPackages © 2026

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