PHPackages                             james2doyle/laravel-scout-sonic - 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. james2doyle/laravel-scout-sonic

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

james2doyle/laravel-scout-sonic
===============================

Sonic driver for Laravel Scout.

v3.0(5y ago)543.0k8MITPHPPHP &gt;=7.1CI failing

Since Apr 8Pushed 5y ago4 watchersCompare

[ Source](https://github.com/james2doyle/laravel-scout-sonic)[ Packagist](https://packagist.org/packages/james2doyle/laravel-scout-sonic)[ RSS](/packages/james2doyle-laravel-scout-sonic/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (4)Dependencies (4)Versions (5)Used By (0)

Laravel Scout Sonic Driver
==========================

[](#laravel-scout-sonic-driver)

Search Eloquent Models using [Sonic](https://github.com/valeriansaliou/sonic) indexes.

1. [Implementation](#implementation)
2. [Installation](#installation)
3. [Usage](#usage)

Implementation

-----------------

[](#implementation-)

When implementing the `toSearchableArray` method, you need to provide an array that will be coerced into a string (the engine just joins with a `' '`) as Sonic can only index strings. So you need to provide a "stringified" (index string) version of your model. The default `toArray` works but it is probably too much noise for reasonable usage.

Here is an example of the string I used when I was developing this Engine:

```
public function toSearchableArray()
{
    return array_filter([$this->display_name, $this->first_name, $this->last_name]);
}
```

For me, this builds a nice string for search that can match on a "name". In my application, the concept of "name" is either the User display name or first/last name.

---

If the locale is known, you can also create the `getSonicLocale()` method on your model, which returns the locale. It will then get passed to the Sonic `PUSH` calls:

```
// an ISO 639-3 locale code eg. eng for English (if set, the locale must be a valid ISO 639-3 code; if set to none, lexing will be disabled; if not set, the locale will be guessed from text)
public function getSonicLocale() {
    return 'none';
}
```

Installation

---------------

[](#installation-)

If you haven't already you should [install Laravel Scout](https://laravel.com/docs/5.8/scout#installation) to your project and apply the `Laravel\Scout\Searchable` trait to any Eloquent models you would like to make searchable.

Install this package via **Composer**

`composer require james2doyle/laravel-scout-sonic`

**Note: if you have Laravel &gt;= 5.5 you can skip this step because of Package Auto-Discovery.**

Next add the ServiceProvider to the Package Service Providers in `config/app.php`

```
/*
 * Package Service Providers...
 */
james2doyle\SonicScout\Providers\SonicScoutServiceProvider::class,
```

Append the default configuration to `config/scout.php`

```
/*
|--------------------------------------------------------------------------
| Sonic Configuration
|--------------------------------------------------------------------------
|
| Here you may configure your Sonic settings.
|
*/

'sonic' => [
    'address' => \env('SONIC_ADDRESS', 'localhost'),
    'port' => \env('SONIC_PORT', 1491),
    'password' => \env('SONIC_PASSWORD'),
    'connection_timeout' => \env('SONIC_CONNECTION_TIMEOUT', 10),
    'read_timeout' => \env('SONIC_READ_TIMEOUT',  5)
],
```

Set `SCOUT_DRIVER=sonic` in your `.env` file

In addition there is no need to use the `php artisan scout:import` command.

Usage

--------

[](#usage-)

Simply call the `search()` method on your `Searchable` models:

`$users = App\User::search('bro')->get();`

Simple constraints can be applied using the `where()` builder method:

`$users = App\User::search('bro')->where('active', 1)->get();`

**Note: Sonic does not support the concept of "where", so the where is applied at the collection level not the query!**

### Pagination

[](#pagination)

Sonic cannot support real pagination because Sonic does not return proper paging or total information. It simply returns all the results for a given query.

There is a naive implementation of pagination in place but it probably isn't perfect as it doesn't take into account the "where" filter.

For more usage information see the [Laravel Scout Documentation](https://laravel.com/docs/5.3/scout).

###  Health Score

35

—

LowBetter than 77% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity33

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor2

2 contributors hold 50%+ of commits

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

Total

4

Last Release

2059d ago

Major Versions

v1.1 → v2.02020-10-14

v2.0 → v3.02020-11-13

PHP version history (2 changes)v1.0PHP &gt;=7.0

v3.0PHP &gt;=7.1

### Community

Maintainers

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

---

Top Contributors

[![manavo](https://avatars.githubusercontent.com/u/259487?v=4)](https://github.com/manavo "manavo (10 commits)")[![james2doyle](https://avatars.githubusercontent.com/u/1425304?v=4)](https://github.com/james2doyle "james2doyle (7 commits)")[![tvercruysse](https://avatars.githubusercontent.com/u/20804569?v=4)](https://github.com/tvercruysse "tvercruysse (6 commits)")

---

Tags

laravelscoutsearchsonic

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/james2doyle-laravel-scout-sonic/health.svg)

```
[![Health](https://phpackages.com/badges/james2doyle-laravel-scout-sonic/health.svg)](https://phpackages.com/packages/james2doyle-laravel-scout-sonic)
```

###  Alternatives

[algolia/scout-extended

Scout Extended extends Laravel Scout adding algolia-specific features

4196.7M6](/packages/algolia-scout-extended)[matchish/laravel-scout-elasticsearch

Search among multiple models with ElasticSearch and Laravel Scout

7491.7M3](/packages/matchish-laravel-scout-elasticsearch)[jeroen-g/explorer

Next-gen Elasticsearch driver for Laravel Scout.

399672.8k](/packages/jeroen-g-explorer)[typesense/laravel-scout-typesense-driver

Laravel Scout Driver for Typesense

146678.3k3](/packages/typesense-laravel-scout-typesense-driver)[zing/laravel-scout-opensearch

Laravel Scout custom engine for OpenSearch

35435.7k](/packages/zing-laravel-scout-opensearch)[romanstruk/manticore-scout-engine

Laravel Manticore Scout Engine

4921.2k](/packages/romanstruk-manticore-scout-engine)

PHPackages © 2026

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