PHPackages                             torann/laravel-hunt - 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. torann/laravel-hunt

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

torann/laravel-hunt
===================

Unified search for Laravel models using Elasticsearch.

0.5.5(9y ago)43751BSD 2-ClausePHPPHP &gt;=5.5.0

Since Nov 9Pushed 8y ago2 watchersCompare

[ Source](https://github.com/Torann/laravel-hunt)[ Packagist](https://packagist.org/packages/torann/laravel-hunt)[ Docs](https://github.com/Torann/laravel-hunt)[ RSS](/packages/torann-laravel-hunt/feed)WikiDiscussions master Synced today

READMEChangelog (7)Dependencies (6)Versions (9)Used By (0)

Laravel Hunt
============

[](#laravel-hunt)

[![Latest Stable Version](https://camo.githubusercontent.com/d994e5d670e74ebb7bd8ebfaa375164768e77a25fa18a1da0df7ef1cd8dba8fe/68747470733a2f2f706f7365722e707567782e6f72672f746f72616e6e2f6c61726176656c2d68756e742f762f737461626c652e706e67)](https://packagist.org/packages/torann/laravel-hunt)[![Total Downloads](https://camo.githubusercontent.com/19d52405fa0e44166c07fddf1115b02f3de7a6dbead1aaf0c32cd8342273e31e/68747470733a2f2f706f7365722e707567782e6f72672f746f72616e6e2f6c61726176656c2d68756e742f646f776e6c6f6164732e706e67)](https://packagist.org/packages/torann/laravel-hunt)[![Patreon donate button](https://camo.githubusercontent.com/f9e075baad95563481d35174d43ef50757281abb6bc795d0f473fad452afa030/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f70617472656f6e2d646f6e6174652d79656c6c6f772e737667)](https://www.patreon.com/torann)[![Donate weekly to this project using Gratipay](https://camo.githubusercontent.com/0eeae019980adaa1dc64842cfb01f3d738c688982ea4eb58094047011cb46704/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f67726174697061792d646f6e6174652d79656c6c6f772e737667)](https://gratipay.com/~torann)[![Donate to this project using Flattr](https://camo.githubusercontent.com/d79e412f78041f87e203449041ad81848a8405cf0f3c622c51e3bad0c2a4b599/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f666c617474722d646f6e6174652d79656c6c6f772e737667)](https://flattr.com/profile/torann)[![Donate to this project using Paypal](https://camo.githubusercontent.com/604e3db9c8751116b3f765aad0353ec7ded655bbe8aaacbc38d8c4a6b784b3ed/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f446f6e6174652d50617950616c2d677265656e2e737667)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=4CJA2A97NPYVU)

Unified search for Laravel models using Elasticsearch. Laravel Hunt uses the [official Elasticsearch PHP API](https://github.com/elasticsearch/elasticsearch-php). To get started, you should have a basic knowledge of how Elasticsearch works (indexes, types, mappings, etc).

Elasticsearch Requirements
==========================

[](#elasticsearch-requirements)

You must be running Elasticsearch 5.0 or higher.

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

[](#installation)

### Composer

[](#composer)

From the command line run:

```
$ composer require torann/laravel-hunt

```

### Laravel

[](#laravel)

Once installed you need to register the service provider with the application. Open up `config/app.php` and find the `providers` key.

```
'providers' => [

    LaravelHunt\LaravelHuntServiceProvider::class,

]
```

### Lumen

[](#lumen)

For Lumen register the service provider in `bootstrap/app.php`.

```
$app->register(LaravelHunt\LaravelHuntServiceProvider::class);
```

### Publish the configurations

[](#publish-the-configurations)

Run this on the command line from the root of your project:

```
$ php artisan vendor:publish --provider="LaravelHunt\LaravelHuntServiceProvider" --tag=config

```

A configuration file will be publish to `config/hunt.php`.

### Indexes and Mapping

[](#indexes-and-mapping)

While you can definitely build your indexes and mapping through the Elasticsearch API, you can also use some helper methods to build indexes and types right from your models.

For custom analyzer, you can set an `settings` property in the `config/hunt.php` file:

```
[
    'settings' => [
         'number_of_shards' => 1,
         'analysis' => [
             'filter' => [
                 'autocomplete_filter' => [
                     'type' => 'edge_ngram',
                     'min_gram' => 1,
                     'max_gram' => 20,
                 ],
             ],
             'analyzer' => [
                 'autocomplete' => [
                     'type' => 'custom',
                     'tokenizer' => 'standard',
                     'filter' => [
                         'lowercase',
                         'autocomplete_filter',
                     ],
                 ],
             ],
         ],
     ],
]
```

For mapping, you can set a `mappingProperties` property in your model and use some mapping functions from there:

```
protected $mappingProperties = [
   'title' => [
        'type' => 'string',
        'analyzer' => 'standard'
    ]
];
```

Artisan Commands
----------------

[](#artisan-commands)

#### `hunt:install`

[](#huntinstall)

Create the Elasticsearch index.

#### `hunt:uninstall`

[](#huntuninstall)

Remove the Elasticsearch index.

#### `hunt:map `

[](#huntmap-model)

Initialize an Eloquent model map.

Arguments:

```
 model               Name or comma separated names of the model(s) to initialize

```

#### `hunt:import `

[](#huntimport-model)

Import all the entries in an Eloquent model. This will also initialize the model's map if one is not already set.

Arguments:

```
 model               Name or comma separated names of the model(s) to index

```

#### `hunt:flush `

[](#huntflush-model)

Flush all of the model's records from the index.

Arguments:

```
 model               Name or comma separated names of the model(s) to index

```

Indexing
--------

[](#indexing)

Once you have added the `LaravelHunt\Huntable` trait to a model, all you need to do is save a model instance and it will automatically be added to your index.

```
$post = new App\Post;

// ...

$post->save();
```

> **Note**: if the model record is already in your index, it will be updated. If it does not exist in the index, it will be added.

Updating Records
----------------

[](#updating-records)

To update an index model, you only need to update the model instance's properties and `save`` the model to your database. Hunt will automatically persist the changes to your search index:

```
$post = App\Post::find(1);

// Update the post...

$post->save();
```

Removing Records
----------------

[](#removing-records)

To remove a record from your index, simply `delete` the model from the database. This form of removal is even compatible with **soft deleted** models:

```
$post = App\Post::find(1);

$post->delete();
```

Searching
---------

[](#searching)

You may begin searching a model using the `search` method. The search method accepts a single string that will be used to search your models. You should then chain the `get` method onto the search query to retrieve the Eloquent models that match the given search query:

```
$posts = App\Post::search('Kitten fluff')->get();
```

Since Hunt searches return a collection of Eloquent models, you may even return the results directly from a route or controller and they will automatically be converted to JSON:

```
use Illuminate\Http\Request;

Route::get('/search', function (Request $request) {
    return App\Post::search($request->search)->get();
});
```

Pagination
----------

[](#pagination)

In addition to retrieving a collection of models, you may paginate your search results using the `paginate` method. This method will return a `Paginator` instance just as if you had paginated a traditional Eloquent query:

```
$posts = App\Post::search('Kitten fluff')->paginate();
```

You may specify how many models to retrieve per page by passing the amount as the first argument to the `paginate` method:

```
$posts = App\Post::search('Kitten fluff')->paginate(15);
```

Once you have retrieved the results, you may display the results and render the page links using Blade just as if you had paginated a traditional Eloquent query:

```

    @foreach ($posts as $post)
        {{ $post->title }}
    @endforeach

{{ $posts->links() }}
```

Multilingual
------------

[](#multilingual)

> This feature is experimental

Laravel Hunt can support multiple languages by appending the language code to the index type, so when the system performs a search it will only look for data that is on in the current system locale suffixed index type. For this to work the model needs to use the `LaravelHunt\Localized` trait or something similar to it and model needs to have the filed `locale`.

For more information see the config file for more details.

###  Health Score

27

—

LowBetter than 47% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity53

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

Recently: every ~20 days

Total

8

Last Release

3315d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1406755?v=4)[Daniel Stainback](/maintainers/torann)[@Torann](https://github.com/Torann)

---

Top Contributors

[![Torann](https://avatars.githubusercontent.com/u/1406755?v=4)](https://github.com/Torann "Torann (21 commits)")

---

Tags

elasticsearchelasticsearch-apieloquent-modelslaravellumenmultilingualunified-searchsearchlaravelelasticsearcheloquentunified searchelasticsearch 5

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/torann-laravel-hunt/health.svg)

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

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3345.1M337](/packages/psalm-plugin-laravel)[kirschbaum-development/eloquent-power-joins

The Laravel magic applied to joins.

1.6k29.9M42](/packages/kirschbaum-development-eloquent-power-joins)[tucker-eric/eloquentfilter

An Eloquent way to filter Eloquent Models

1.8k5.0M31](/packages/tucker-eric-eloquentfilter)[cybercog/laravel-love

Make Laravel Eloquent models reactable with any type of emotions in a minutes!

1.2k322.4k1](/packages/cybercog-laravel-love)[cviebrock/eloquent-taggable

Easy ability to tag your Eloquent models in Laravel.

567714.4k4](/packages/cviebrock-eloquent-taggable)[reedware/laravel-relation-joins

Adds the ability to join on a relationship by name.

2111.2M16](/packages/reedware-laravel-relation-joins)

PHPackages © 2026

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