PHPackages                             searchkit/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. [Database &amp; ORM](/categories/database)
4. /
5. searchkit/searchable

ActiveLibrary[Database &amp; ORM](/categories/database)

searchkit/searchable
====================

A Laravel package to make Eloquent models searchable using a simple trait

v1.0.3(2mo ago)011MITPHPPHP ^7.4 || ^8.0CI passing

Since Apr 28Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/Sandezh/laravel-searchable)[ Packagist](https://packagist.org/packages/searchkit/searchable)[ RSS](/packages/searchkit-searchable/feed)WikiDiscussions main Synced 3w ago

READMEChangelog (1)Dependencies (4)Versions (5)Used By (0)

Laravel Searchable (Sift)
=========================

[](#laravel-searchable-sift)

A lightweight and powerful Laravel package to make your Eloquent models searchable using a reusable trait. Designed with performance and real-world repository patterns in mind.

Features
--------

[](#features)

- **Trait-based architecture**: Simply add `use Sift;` to any model.
- **Relational Search**: Search across model relationships effortlessly.
- **JSON Search**: Deep search support for JSON columns.
- **Query Scope**: Provides a clean `search()` scope for your query builder.
- **Repository Compatible**: Perfect for projects using the Repository or Service pattern.
- **Lightweight**: Zero unnecessary dependencies, optimized for speed.
- **Customizable**: Configure operators, date formats, and case sensitivity.

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

[](#installation)

You can install the package via composer:

```
composer require searchkit/searchable
```

Configuration
-------------

[](#configuration)

Publish the configuration file to customize the search behavior:

```
php artisan vendor:publish --provider="Searchkit\Searchable\SiftServiceProvider" --tag="config"
```

The published configuration file `config/searchable.php` allows you to control the search behavior globally:

- **`case_sensitive`**: Toggle between case-sensitive and case-insensitive searching.
- **`custom_operators`**: Set the default SQL operator (default is `LIKE`).
- **`enable_exact_match_search`**: When `true`, forces `=` operator for all searches.
- **`default_exclude_fields`**: Globally exclude columns like `id` or `password` from dynamic searches.
- **`custom_formats`**: Define how `date`, `time`, and `timestamp` fields are formatted at the database level during search.

Usage
-----

[](#usage)

### 1. Setup BaseModel (Optional but Recommended)

[](#1-setup-basemodel-optional-but-recommended)

It is common practice to include the trait in a `BaseModel` so it's available across all your models.

```
namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Searchkit\Searchable\Sift;

class BaseModel extends Model
{
    use Sift;
}
```

### 2. Configure Your Models

[](#2-configure-your-models)

Extend the `BaseModel` and define which fields should be searchable.

```
namespace App\Models;

class Product extends BaseModel
{
    /**
     * Standard fields on the current model (populated in boot).
     */
    protected static $searchable = [];

    /**
     * Fields on model relationships.
     */
    protected static $relation_searchable = [
        'category' => ['title']
    ];

    /**
     * JSON columns on the current model.
     */
    protected static $json_searchable = [
        'data' => '*',           // Search all keys in the 'data' JSON column
        'meta' => ['brand']      // Search only the 'brand' key in the 'meta' JSON column
    ];

    /**
     * JSON columns on model relationships.
     */
    protected static $json_relation_searchable = [
        'category' => [
            'data' => '*',               // Search all keys in category's 'data' JSON
            'settings' => ['icon', 'type'] // Search specific keys in category's 'settings' JSON
        ]
    ];

    protected static function boot(): void
    {
        parent::boot();

        // Dynamically include all columns except 'slug' and 'deleted_at'
        self::$searchable = self::getSearchableFields(['slug', 'deleted_at']);
    }

    public function category()
    {
        return $this->belongsTo(Category::class);
    }
}
```

Detailed Search Configurations
------------------------------

[](#detailed-search-configurations)

The package supports a variety of configuration styles to suit your needs:

### Standard Search

[](#standard-search)

You can either explicitly define searchable fields or dynamically include all columns while excluding specific ones.

#### Option A: Explicit Fields (Recommended for control)

[](#option-a-explicit-fields-recommended-for-control)

Only the specified columns will be searchable.

```
protected static $searchable = ['title', 'description', 'sku'];
```

#### Option B: Dynamic Fields (Recommended for speed)

[](#option-b-dynamic-fields-recommended-for-speed)

Automatically make all columns searchable while excluding specific ones using the `boot()` method.

```
protected static $searchable = [];

protected static function boot(): void
{
    parent::boot();

    // Automatically make all columns searchable except 'slug' and 'deleted_at'
    self::$searchable = self::getSearchableFields(['slug', 'deleted_at']);
}
```

### Relationship Search

[](#relationship-search)

Search columns in related tables.

```
protected static $relation_searchable = [
    'category' => ['title'],
    'tags' => ['name']
];
```

### JSON Search (Current Model)

[](#json-search-current-model)

Search within JSON columns using different levels of granularity.

```
// Case 1: Search all keys in a JSON column
protected static $json_searchable = ['data'];
// OR
protected static $json_searchable = ['data' => '*'];

// Case 2: Search specific keys in a JSON column
protected static $json_searchable = [
    'data' => ['brand', 'model']
];
```

### JSON Search (Relationships)

[](#json-search-relationships)

Search within JSON columns belonging to related models.

```
// Case 1: Search all keys in a related JSON column
protected static $json_relation_searchable = [
    'category' => [
        'data' => '*'
    ]
];

// Case 2: Search specific keys in a related JSON column
protected static $json_relation_searchable = [
    'category' => [
        'data' => ['icon', 'type']
    ]
];
```

### 3. Basic Search Usage

[](#3-basic-search-usage)

The package provides a `search()` scope that you can chain onto any Eloquent query.

```
// Search for products matching "iphone" in any searchable field or category title
$products = Product::query()->search('iphone')->get();
```

---

Real-World Usage (Repository Pattern)
-------------------------------------

[](#real-world-usage-repository-pattern)

This package is built to shine in professional environments using the Repository pattern.

### Base Repository Example

[](#base-repository-example)

```
namespace App\Repositories;

use Illuminate\Database\Eloquent\Builder;

abstract class BaseRepository
{
    protected function getResult(Builder $query, ?array $data = null)
    {
        // Apply search if search_term is provided
        if (isset($data['search_term'])) {
            $query->search($data['search_term']);
        }

        // Apply other common filters (date, pagination, etc.)
        return $query->latest()->paginate($data['per_page'] ?? 15);
    }
}
```

### Product Repository Implementation

[](#product-repository-implementation)

```
namespace App\Repositories;

use App\Models\Product;

class ProductRepository extends BaseRepository
{
    public function getAll(?array $data = null)
    {
        $query = Product::query()->with('category');

        return $this->getResult($query, $data);
    }
}
```

---

Sample Application
------------------

[](#sample-application)

Want to see **Laravel Searchable (Sift)** in action inside a real Laravel project?

Check out the official sample application that demonstrates how to integrate the package using models, repositories, and controllers in a full Laravel setup:

👉 **[laravel-searchable-sample-app](https://github.com/Sandezh/laravel-searchable-sample-app)**

The sample app includes:

- A complete Laravel project wired up with `searchkit/searchable`
- `BaseModel` and model configurations with standard, relational, and JSON search fields
- A `BaseRepository` and concrete repositories using the `search()` scope
- Database seeders to populate test data and verify search results out of the box

---

Requirements
------------

[](#requirements)

- **PHP**: ^7.4 | ^8.0
- **Laravel**: ^8.0 | ^9.0 | ^10.0 | ^11.0 | ^12.0 | ^13.0

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

36

—

LowBetter than 79% of packages

Maintenance83

Actively maintained with recent releases

Popularity5

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity42

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 ~1 days

Total

4

Last Release

85d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/116537542?v=4)[sandezh](/maintainers/sandezh)[@Sandezh](https://github.com/Sandezh)

---

Top Contributors

[![Sandezh](https://avatars.githubusercontent.com/u/116537542?v=4)](https://github.com/Sandezh "Sandezh (27 commits)")

---

Tags

searchlaravelmodeleloquentsearchablelaravel-searchableeloquent-searchmodel\_searcheloquent-searchablelaravel-searchmodel searchable

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[mongodb/laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel

7.1k8.4M98](/packages/mongodb-laravel-mongodb)[tucker-eric/eloquentfilter

An Eloquent way to filter Eloquent Models

1.8k5.1M36](/packages/tucker-eric-eloquentfilter)[psalm/plugin-laravel

Psalm plugin for Laravel

3345.3M347](/packages/psalm-plugin-laravel)[yajra/laravel-oci8

Oracle DB driver for Laravel via OCI8

8793.2M25](/packages/yajra-laravel-oci8)[glushkovds/phpclickhouse-laravel

Adapter of the most popular library https://github.com/smi2/phpClickHouse to Laravel

2051.5M2](/packages/glushkovds-phpclickhouse-laravel)[jedrzej/searchable

Searchable trait for Laravel's Eloquent models - filter your models using request parameters

127270.5k5](/packages/jedrzej-searchable)

PHPackages © 2026

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