PHPackages                             soraspire/laravel-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. soraspire/laravel-searchable

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

soraspire/laravel-searchable
============================

A Laravel package that provides a flexible Searchable trait with support for custom operators (like, regex, soundex, fulltext, etc.)

1.0.0(8mo ago)22MITPHPPHP &gt;=8.1

Since Aug 28Pushed 8mo agoCompare

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

READMEChangelogDependencies (1)Versions (2)Used By (0)

Laravel Searchable
==================

[](#laravel-searchable)

A lightweight Laravel package that enables advanced searching &amp; sorting directly from URL query parameters. Designed to let Frontend (FE) fully control search logic without touching Backend code. Supports custom operators such as `like`, `regex`, `soundex`, `fulltext`, and more.

---

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

[](#requirements)

- PHP 8.1 or higher
- MySQL 8.0+
- Laravel 10.0+

Features
--------

[](#features)

⚡ Fast attribute search with Eloquent

🎛️ Advanced search from request

🔍 Search through single or multiple columns

🔗 Search through (nested) Relationships

📖 Support for Full-Text Search, Soundex Search

↕️ Supports sorting on attributes and first-level relationships

⚙️ Define your own operators

🛡️ Whitelist allowed columns

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

[](#installation)

You can install the package via composer:

```
composer require soraspire/laravel-searchable
```

Publish Config
--------------

[](#publish-config)

```
php artisan vendor:publish --tag=config --provider="Soraspire\\Searchable\\ServiceProvider"
```

Usage
-----

[](#usage)

In your model:

```
use Soraspire\Searchable\Traits\Searchable;

class Post extends Model
{
    use Searchable;

    protected array $searchable = [
        'title',
        'content',
        'comments' => ['content'],
        'user'     => ['id', 'name', 'email'],
    ];
}
```

Now you can search with custom operators:

```
Post::query()->search();
```

Search directly from URL query params:

```
GET /posts?title__like=Laravel
```

In the above query:

`title__like=Laravel` → find posts with title containing "Laravel"

### Search with multiple columns

[](#search-with-multiple-columns)

Search across multiple columns in the same table by passing multiple query conditions.

```
GET /posts?title__like=Laravel&content__like=Laravel
```

### Search through relationships

[](#search-through-relationships)

Supports searching through `relationships` (e.g., comments, user). You can combine conditions from both the main model and related models.

```
GET /posts?title__like=Laravel&content__like=Laravel&comments__content__en=Laravel&comments__user__name__eq=Laravel
```

### FULLTEXT search

[](#fulltext-search)

Performs a `full-text search`, allowing more accurate matching across multiple keywords. Works best on columns with a fulltext index.

```
GET /posts?content__fulltext=Laravel%20Eloquent
```

### SOUNDEX (raw operator)

[](#soundex-raw-operator)

Searches using the `SOUNDEX` operator, which matches words that sound similar. Useful for names or terms with different spellings but similar pronunciation.

```
GET /posts?content__soundex=Laravel
```

### Custom Operators

[](#custom-operators)

You can define your own operators inside the config/searchable.php file.

```
'today' => ['type' => 'raw', 'sql' => 'DATE({col}) = CURDATE()'],
```

Now you can search using your custom operators:

```
GET /posts?content__today
```

### Supported Query Operators

[](#supported-query-operators)

OperatorTypeSQL / PatternDescriptioneqbasic=Equalnot\_eqbasic!=Not equalltbasic&lt;Less thanltebasic&lt;=Less than or equalgtbasic&gt;Greater thangtebasic&gt;=Greater than or equalcontlike%{val}%Containsstartlike{val}%Starts withendlike%{val}Ends withlikelike{val}Exact likeinin-Value in listnot\_innot\_in-Value not in listbetweenbetween-Value between two valuesnot\_betweennot\_between-Value not between two valuesnullnull-Is nullnot\_nullnot\_null-Is not nullpresentpresent-Field existsblankblank-Field is blankyearrawYEAR({col}) = ?Match yearmonthrawMONTH({col}) = ?Match monthdaterawDATE({col}) = ?Match datebefore\_todayrawDATE({col}) &lt; CURDATE()Date before todayafter\_todayrawDATE({col}) &gt; CURDATE()Date after todaytodayrawDATE({col}) = CURDATE()Todayregexpraw{col} REGEXP ?Match regexnot\_regexpraw{col} NOT REGEXP ?Not match regexsoundexrawSOUNDEX({col}) = SOUNDEX(?)Match similar sounding wordsfulltextrawMATCH({col}) AGAINST (? IN BOOLEAN MODE)Full-text search### Sorting on attributes

[](#sorting-on-attributes)

You can sort the result attributes using the order query parameter.

```
GET /posts?order=title__asc
```

Sorting on first-level relationships

```
GET /posts?order=title__asc,comments__user_id__desc
```

License
-------

[](#license)

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

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance59

Moderate activity, may be stable

Popularity5

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity44

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

Unknown

Total

1

Last Release

258d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/35c63ddb7dbd289278a12d2aff073bc00028ac6dca6783966e4dd275f056b229?d=identicon)[soraspire](/maintainers/soraspire)

---

Top Contributors

[![soraspire](https://avatars.githubusercontent.com/u/75217040?v=4)](https://github.com/soraspire "soraspire (3 commits)")

---

Tags

searchlaraveleloquenttraitqueryfilter

### Embed Badge

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

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

###  Alternatives

[tucker-eric/eloquentfilter

An Eloquent way to filter Eloquent Models

1.8k4.8M26](/packages/tucker-eric-eloquentfilter)[mehdi-fathi/eloquent-filter

Eloquent Filter adds custom filters automatically to your Eloquent Models in Laravel.It's easy to use and fully dynamic, just with sending the Query Strings to it.

450191.6k1](/packages/mehdi-fathi-eloquent-filter)[aldemeery/sieve

A simple, clean and elegant way to filter Eloquent models.

1396.3k](/packages/aldemeery-sieve)[jedrzej/searchable

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

127259.1k5](/packages/jedrzej-searchable)

PHPackages © 2026

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