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

Abandoned → [masterro/laravel-searchable](/?search=masterro%2Flaravel-searchable)Library[Search &amp; Filtering](/categories/search)

masterro/searchable
===================

Simple fulltext search though Eloquent models

v1.1.0(5y ago)96983MITPHPPHP ^7.2|^8.0

Since Feb 1Pushed 4y ago2 watchersCompare

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

READMEChangelog (10)Dependencies (5)Versions (18)Used By (0)

 [ ![Latest Stable Version](https://camo.githubusercontent.com/47cf34188fd90aca91a56f79bb95ab5314b916ed855d9c23648a41cd3fb4653c/68747470733a2f2f706f7365722e707567782e6f72672f6d6173746572726f2f6c61726176656c2d73656172636861626c652f762f737461626c65) ](https://packagist.org/packages/masterro/laravel-searchable) [ ![Total Downloads](https://camo.githubusercontent.com/a2beb952177ef7c7050896c9832067aac189555f4e1577fd983172894217859d/68747470733a2f2f706f7365722e707567782e6f72672f6d6173746572726f2f6c61726176656c2d73656172636861626c652f646f776e6c6f616473) ](https://packagist.org/packages/masterro/laravel-searchable) [ ![Build Status](https://github.com/MasterRO94/laravel-searchable/workflows/Tests/badge.svg) ](https://github.com/MasterRO94/laravel-searchable/actions) [ ![Build status](https://camo.githubusercontent.com/32da7b21844fb5efa110cb47293e995713438d7f6792508a9764b632463a7dd3/68747470733a2f2f7472617669732d63692e6f72672f4d6173746572524f39342f6c61726176656c2d73656172636861626c652e737667) ](https://travis-ci.org/MasterRO94/laravel-searchable) [ ![License](https://camo.githubusercontent.com/0d487ba450b6d673b0e81e34cb829d341eb6e89c43e978d38eabc59e42755605/68747470733a2f2f706f7365722e707567782e6f72672f6d6173746572726f2f6c61726176656c2d73656172636861626c652f6c6963656e7365) ](https://github.com/MasterRO94/laravel-searchable/blob/master/LICENCE.txt)

Laravel simple FULLTEXT search through multiple Eloquent models
===============================================================

[](#laravel-simple-fulltext-search-through-multiple-eloquent-models)

This is a small Laravel package allows you to make a global search though multiple Eloquent models and get ordered by relevance collection of results. It uses MATCH AGAINST MySQL queries.

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

[](#installation)

### Step 1: Composer

[](#step-1-composer)

From the command line, run:

```
composer require masterro/laravel-searchable

```

### Step 2: Service Provider

[](#step-2-service-provider)

If you do not use laravel package **auto-discovery** you need to register the service provider, open `config/app.php` and, within the `providers` array, append:

```
MasterRO\Searchable\SearchableServiceProvider::class
```

Usage
-----

[](#usage)

Register your search models in AppServiceProvider or create your custom one

```
Searchable::registerModels([
    Post::class,
    Article::class,
    User::class,
]);
```

Then you should implement MasterRO\\Searchable\\SearchableContract by each registered model, or it will be skipped and define `searchable` method

```
public static function searchable(): array
{
    return ['title', 'description'];
}
```

**Make sure you added fulltext indicies to your tables**

```
public function up()
    {
        Schema::create('posts', function (Blueprint $table) {
            $table->id();

            $table->string('title');
            $table->longText('description');
            $table->dateTime('published_at')->nullable();

            $table->timestamps();
        });

        DB::statement('ALTER TABLE posts ADD FULLTEXT search(title, description)');
    }
```

Now you can make search in your controller or where you want

```
public function search(Request $request, Searchable $searchable)
{
    $query = trim($request->input('q'));

    if (mb_strlen($query) < 3) {
        return back()->withInput()->withErrors([
            'search_error' => __('messages.search_error')
        ]);
    }

    return view('search.index')->with('results', $searchable->search($query));
}
```

Runtime search model switching

```
$result = $this->searchable->searchModel(Post::class, 'consequatur');
```

```
$result = $this->searchable->searchModel([Article::class, Post::class], 'consequatur');
```

### Filtering

[](#filtering)

#### Model filter

[](#model-filter)

Search results can be filtered by adding the `filterSearchResults()` in your model (like Eloquent global scope)

```
class User extends Model implements SearchableContract
{
    public function posts() {
        return $this->hasMany(Post::class);
    }

    public function filterSearchResults($query) {
        return $query->whereHas('posts', function ($query) {
            $query->where('is_published', true);
        });
    }
}
```

> The example code above will filter the search results and will only return users which have published posts.

#### Runtime filter

[](#runtime-filter)

Search results can be filtered by adding custom filter callback

```
$result = $this->searchable
    ->withFilter(function (Builder $query) {
        return $query->getModel() instanceof Post
            ? $query->where('description', '!=', 'Doloremque iure sequi quos sequi consequatur.')
            : $query;
    })
    ->search('Dolorem');
```

#### Disabling model filter

[](#disabling-model-filter)

Model filters can be skipped in runtime like Eloquent global scopes.

```
$result = $this->searchable->withoutModelFilters()->search('quia est ipsa molestiae hic');
```

You can specify models to skip filters for

```
$result = $this->searchable
    ->withoutModelFilters(Post::class)
    ->search('quia est ipsa molestiae hic');
```

or

```
$result = $this->searchable
    ->withoutModelFilters([Article::class, Post::class])
    ->search('quia est ipsa molestiae hic');
```

### Eager load (N+1 issue)

[](#eager-load-n1-issue)

For preventing N+1 issue you can eager load relationships for search results

```
$result = $this->searchable
    ->with([Article::class => 'author'])
    ->search('consequatur');
```

```
$result = $this->searchable
    ->with([
        Article::class => [
            'author' => function ($query) {
                return $query->where('active', true);
            },
        ],
    ])
    ->searchModel(Article::class, 'consequatur');
```

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity21

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity77

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

Recently: every ~336 days

Total

15

Last Release

1977d ago

Major Versions

0.3.2 → v1.0.02020-05-06

PHP version history (3 changes)0.1.0PHP ^7.0

v1.0.0PHP ^7.1

v1.1.0PHP ^7.2|^8.0

### Community

Maintainers

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

---

Top Contributors

[![MasterRO94](https://avatars.githubusercontent.com/u/7365389?v=4)](https://github.com/MasterRO94 "MasterRO94 (64 commits)")

---

Tags

searchlaravelfulltextglobal-search

### Embed Badge

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

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

###  Alternatives

[laravel/scout

Laravel Scout provides a driver based solution to searching your Eloquent models.

1.7k49.4M479](/packages/laravel-scout)[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)[typesense/laravel-scout-typesense-driver

Laravel Scout Driver for Typesense

144637.2k3](/packages/typesense-laravel-scout-typesense-driver)[gtk/larasearch

A driver based solution to searching your Eloquent models supports Laravel 5.2 and Elasticsearch engine.

133.9k](/packages/gtk-larasearch)

PHPackages © 2026

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