PHPackages                             baethon/eloquent-searchable-scope - 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. baethon/eloquent-searchable-scope

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

baethon/eloquent-searchable-scope
=================================

An Eloquent scope for building a search query using LIKE statements

v2.0.1(2y ago)01.9k↓100%[1 issues](https://github.com/baethon/eloquent-searchable-scope/issues)MITPHPPHP ^8.1

Since Feb 6Pushed 2y ago1 watchersCompare

[ Source](https://github.com/baethon/eloquent-searchable-scope)[ Packagist](https://packagist.org/packages/baethon/eloquent-searchable-scope)[ RSS](/packages/baethon-eloquent-searchable-scope/feed)WikiDiscussions 2.x Synced today

READMEChangelog (5)Dependencies (2)Versions (8)Used By (0)

baethon/eloquent-searchable-scope
=================================

[](#baethoneloquent-searchable-scope)

An Eloquent scope for building a search query using LIKE statements, which also supports searching using relations.

```
$foundPosts = Post::query()
    ->search($search)
    ->get();
```

Installation
============

[](#installation)

```
composer require baethon/eloquent-searchable-scope

```

Model configuration
===================

[](#model-configuration)

Import `Searchable` trait and use it in model:

```
namespace App\Models;

use Baethon\Laravel\Scopes\Searchable;

class Post extends Model
{
    use Searchable;
}
```

Trait requires defining the `getSearchableOptions()` method:

```
namespace App\Models;

use Baethon\Laravel\Scopes\Searchable;
use Baethon\Laravel\Scopes\SearchableOptions;

class Post extends Model
{
    use Searchable;

    public function getSearchableOptions(): SearchableOptions
    {
        return SearchableOptions::defaults()
            ->fields(['topic', 'text', 'user.email'];
    }
}
```

Note: `user.email` refers to `user` relation. It has to be defined in the model.

Available Options
-----------------

[](#available-options)

The `SearchableOptions` provides the ability to customize the search functionality in a few ways:

- `breakToWords()` - splits the search term into words and searches against each of them.
- `minTermLength(int $minLength)` - rejects any string/word that is shorter than the specified number of characters.
- `fields(array $fields)` - specifies the fields to be used in the search.

The `SearchableOptions::defaults()` is equivalent of:

```
(new SearchableOptions)->minTermLength(3);
```

Overloading search options
--------------------------

[](#overloading-search-options)

When using the `search()` scope, it is possible to define the searchable fields.

```
$foundPosts = Post::query()
    ->search($search, [
        'title',
    ])
    ->get();
```

or, pass custom options object:

```
$foundPosts = Post::query()
    ->search($search, SearchableOptions::defaults()->fields(['title'])
    ->get();
```

If passing a custom options object, ensure that the searchable fields are defined.

Nothing new here!
=================

[](#nothing-new-here)

The idea for this scope has been previously discussed in various places, such as [🔗 here](https://freek.dev/1182-searching-models-using-a-where-like-query-in-laravel) and [🔗 here](https://laravel-tricks.com/tricks/eloquents-dynamic-scope-search-trait). However, since it can be difficult to locate these resources every time one needs them, I have created a package that simplifies the installation process. It is important to note that this package does not introduce any novel concepts.

Testing
=======

[](#testing)

```
composer test

```

###  Health Score

32

—

LowBetter than 74% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity66

Established project with proven stability

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

Recently: every ~182 days

Total

8

Last Release

949d ago

Major Versions

v1.1.0 → v2.0.02023-05-07

### Community

Maintainers

![](https://www.gravatar.com/avatar/488bdbbb3187d1f4f6d9c92f0c716ad413f5e7fe53d3ec5ffefb37cfcad4ecf6?d=identicon)[radmen](/maintainers/radmen)

---

Top Contributors

[![radmen](https://avatars.githubusercontent.com/u/1190255?v=4)](https://github.com/radmen "radmen (25 commits)")

---

Tags

eloquenteloquent-modelslaravelscopesearchsearchlaraveleloquentscope

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/baethon-eloquent-searchable-scope/health.svg)

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

###  Alternatives

[tucker-eric/eloquentfilter

An Eloquent way to filter Eloquent Models

1.8k4.7M23](/packages/tucker-eric-eloquentfilter)[jedrzej/searchable

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

127256.0k4](/packages/jedrzej-searchable)[lacodix/laravel-model-filter

A Laravel package to filter, search and sort models with ease while fetching from database.

17648.2k](/packages/lacodix-laravel-model-filter)

PHPackages © 2026

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