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

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

wkjagt/searchable
=================

Make Laravel models instantly searchable, and automatically indexed using Elastic Search.

10521[2 issues](https://github.com/wkjagt/laravel-searchable/issues)PHP

Since Dec 9Pushed 11y ago1 watchersCompare

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

READMEChangelogDependenciesVersions (1)Used By (0)

laravel-searchable
==================

[](#laravel-searchable)

*Make Laravel models instantly searchable, and automatically indexed using Elastic Search.*

**Work in progress**

Adding search functionality to a laravel model only requires using a trait. Using the `SearchableTrait` in your modle will enable a model observer that acts on the `created`, `updated` and `deleted` events to keep your indexes up to date.

The trait adds a `search` method to your model that makes it easy to search Elastic Search for hits.

The provided facade allows similar functionality, and the added ability to search in multiple document types (i.e. models) at once.

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

[](#installation)

### Composer

[](#composer)

Include the package in your composer file, and run composer update.

I'm still working on this, but `dev-master` will change to a stable tag as soon as I have one ready.

```
{
  "require" : {
     ...
    "wkjagt/searchable": "dev-master"
  }
}
```

### Service provider

[](#service-provider)

Add the ServiceProvider to your `app.php`:

```
'providers' => [
    ...
    'Searchable\SearchableServiceProvider'
]
```

### Searchable Facade

[](#searchable-facade)

If you want to use the Searchable facade, add it to your aliases in `app.php`:

```
'aliases' => [
    ...
    'Searchable'      => 'Searchable\SearchableFacade'
]
```

### Searchable Trait

[](#searchable-trait)

Add the `SearchableTrait` to the models you want indexed. For example:

```
class Thing extends Model {

    use SearchableTrait;

    ...
}
```

That's all you need to get started. Newly created `Thing` models will be automatically indexed. By default, all models will be added to a `default` index, and the fully qualified class name will be used as the document type (where backslashes are replaced by dots). This is fine for normal usage, but can be modified by adding static properties to your model:

```
class Thing extends Model {

    use SearchableTrait;

    public static $searchDocumentType = 'thing';

    public static $searchIndexName = 'my_index';
}
```

### Searching

[](#searching)

Searching can be done in two ways. `SearchableTrait` adds a `search` method to your model, which accepts one argument: an Elastic Search query. For example:

```
$query = [ 'filtered' => [
    'query' => [ 'match' => [ 'name' => 'some_name' ]],
    'filter' => [ 'term' => [ 'user_id' => 14 ]],
]];

$hits = Thing::search($query);
```

You can also search multiple models at once using the Searchable facade, which uses the native Elastic Search way of searching in multiple indexes/document types. The search method on `Searchable` takes an array of fully qualified class names of models, and needs to be chained to the `withSearch` method. An example:

```
$query = [ 'filtered' => [
    'query' => [ 'match' => [ 'name' => 'some_name' ]],
    'filter' => [ 'term' => [ 'user_id' => 14 ]],
]];

$hits = Searchable::search(['Thing', 'OtherThing'])->withQuery($query);
```

The results are returned as an array of `Searchable\SearchResult` instances, which are simple value objects, with two public properties:

- `hit`: a hydrated Laravel Model
- `score` : the search score

### Indexing existing models

[](#indexing-existing-models)

When adding Searchable to an existing project, you probably want to index your existing models. The added `searchable:indexall` artisan command adds this functionality to each model that uses `SearchableTrait`. To index all resources for a given model, run the command, passing the fully qualified class name as argument, replacing any backslashes with forward slashes:

```
./artisan searchable:indexall Namespace/Of/Your/Model

```

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance16

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity41

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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/6a08b8e66af74c9c026531b1cd2beed788a544e0526d678a02a2dfc0e3305dbb?d=identicon)[wkjagt](/maintainers/wkjagt)

---

Top Contributors

[![wkjagt](https://avatars.githubusercontent.com/u/327048?v=4)](https://github.com/wkjagt "wkjagt (31 commits)")

### Embed Badge

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

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

###  Alternatives

[ruflin/elastica

Elasticsearch Client

2.3k50.4M203](/packages/ruflin-elastica)[opensearch-project/opensearch-php

PHP Client for OpenSearch

15024.3M65](/packages/opensearch-project-opensearch-php)[mailerlite/laravel-elasticsearch

An easy way to use the official PHP ElasticSearch client in your Laravel applications.

934529.3k2](/packages/mailerlite-laravel-elasticsearch)[massive/search-bundle

Massive Search Bundle

721.4M13](/packages/massive-search-bundle)[outl1ne/nova-multiselect-filter

Multiselect filter for Laravel Nova.

45802.7k3](/packages/outl1ne-nova-multiselect-filter)[handcraftedinthealps/zendsearch

a general purpose text search engine written entirely in PHP 5

39921.0k35](/packages/handcraftedinthealps-zendsearch)

PHPackages © 2026

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