PHPackages                             provision/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. [Database &amp; ORM](/categories/database)
4. /
5. provision/searchable

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

provision/searchable
====================

Searchable indexing with MySQL full text for Laravel

1.0.9(5y ago)228.4k8[1 issues](https://github.com/ProVisionBG/searchable/issues)[1 PRs](https://github.com/ProVisionBG/searchable/pulls)MITPHPPHP &gt;=7.1.3

Since Jun 29Pushed 2y ago2 watchersCompare

[ Source](https://github.com/ProVisionBG/searchable)[ Packagist](https://packagist.org/packages/provision/searchable)[ Docs](https://github.com/provisionbg/searchable)[ RSS](/packages/provision-searchable/feed)WikiDiscussions master Synced 2w ago

READMEChangelog (10)Dependencies (3)Versions (9)Used By (0)

[![Build Status](https://camo.githubusercontent.com/46727e88d3b8c6404cdc9bd606be731df5360f5fb0b174c979348076101d8115/68747470733a2f2f7472617669732d63692e6f72672f50726f566973696f6e42472f73656172636861626c652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/ProVisionBG/searchable)

Laravel MySQL fulltext search
=============================

[](#laravel-mysql-fulltext-search)

This package creates a MySQL fulltext index for models and enables you to search through those.

Requirements
------------

[](#requirements)

- Laravel &gt;= 5.7
- MySQL &gt;= 5.6 / MariaDB &gt;= 10.0.15

#### Important!

[](#important)

In `config/database.php` set

```
'mysql' => [
...
    'strict' => false,
...
]
```

Install
-------

[](#install)

1. Install with composer `composer require provision/searchable`.
2. Publish migrations and config `php artisan vendor:publish --tag=searchable`
3. Migrate the database `php artisan migrate`

Usage
-----

[](#usage)

The package uses a model observer to update the index when models change. If you want to run a full index you can use the console commands.

### Models

[](#models)

Add the `SearchableTrait` trait to the model you want to have indexed and define the columns you'd like to index as title and content.

#### Example

[](#example)

```
class Clients extends Model
{

    use \ProVision\Searchable\Traits\SearchableTrait;

    /**
     * @inheritDoc
     */
    protected function getSearchableTitleColumns(): array
    {
        return [
            'name'
        ];
    }

    /**
     * @inheritDoc
     */
    protected function getSearchableContentColumns(): array
    {
        return [
            'description',
            'address',
            'vat_number',
            'contacts.value',
            'contactPersons.first_name',
            'contactPersons.last_name',
            'contactPersons.contacts.value',
        ];
    }

}

```

You can use a dot notation to query relationships for the model, like `contacts.value`.

### Relation model indexing

[](#relation-model-indexing)

On related model for indexing use `SearchableRelationTrait` and method `getSearchableRelationName` to return relation name.

Listen for changes on relation and update parent model

#### Example

[](#example-1)

```
class Contact extends Model
{
    use \ProVision\Searchable\Traits\SearchableRelationTrait;

     /**
     * @return MorphTo
     */
    public function contactable()
    {
        return $this->morphTo();
    }

    /**
     * @inheritDoc
     */
    static function getSearchableRelationName(): string
    {
        return 'contactable';
    }
}

```

### Searching

[](#searching)

You can search using the `search` method.

```
$clientsCollection = Clients::search('John Doe')->paginate();

```

#### Search with specific fulltext search mode

[](#search-with-specific-fulltext-search-mode)

```
use ProVision\Searchable\SearchableModes;
---
$clientsCollection = Clients::search('John Doe', SearchableModes::Boolean)->paginate();

```

Available modes

- `NaturalLanguage` - IN NATURAL LANGUAGE MODE
- `NaturalLanguageWithQueryExpression` - IN NATURAL LANGUAGE MODE WITH QUERY EXPANSION
- `Boolean` - IN BOOLEAN MODE
- `QueryExpression` - WITH QUERY EXPANSION

MySQL fulltext search documentation:

#### Search with relations &amp; additional wheres

[](#search-with-relations--additional-wheres)

```
$clientsCollection = Clients::search('John Doe')->where('active', 1)->with(['contacts'])->paginate();

```

#### Order searchable score

[](#order-searchable-score)

```
$clientsCollection = Clients::search('John Doe')->searchableOrder('asc')->paginate();

```

Available options:

- `ASC`
- `DESC`

### Commands

[](#commands)

#### searchable:index

[](#searchableindex)

Index all models for a certain class

```
 php artisan  searchable:index

Usage:
  searchable:index  {id?}

Arguments:
  model_class           Classname of the model to index
  id                    Model id to index (optional)

```

##### Example

[](#example-2)

- Indexing all clients

`php artisan  searchable:index "\App\Models\Client"`

- Indexing specific client by id

`php artisan  searchable:index "\App\Models\Client" 1`

#### searchable:unindex

[](#searchableunindex)

UnIndex all models for a certain class

```
 php artisan  searchable:unindex

Usage:
  searchable:unindex  {id?}

Arguments:
  model_class           Classname of the model to index
  id                    Model id to unindex (optional)

```

##### Example

[](#example-3)

- UnIndexing all clients

`php artisan  searchable:unindex "\App\Models\Client"`

- UnIndexing specific client by id

`php artisan  searchable:unindex "\App\Models\Client" 1`

Config options
--------------

[](#config-options)

### `db_connection`

[](#db_connection)

Choose the database connection to use, defaults to the default database connection. When you are NOT using the default database connection, this MUST be set before running the migration to work correctly.

### `table_name`

[](#table_name)

Table name of index

### `command_prefix`

[](#command_prefix)

Prefix of commands

### `weight.title`, `weight.content`

[](#weighttitle-weightcontent)

Results on `title` or `content` are weighted in the results. Search result score is multiplied by the weight in this config

### `cleaners`

[](#cleaners)

Clean searching keywords for prevent breaking the MySQL query.

Testing
-------

[](#testing)

```
$ composer test
```

###  Health Score

33

—

LowBetter than 72% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity32

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 97.7% 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 ~49 days

Total

7

Last Release

1890d ago

PHP version history (3 changes)1.0.0PHP ^7.1.3

1.0.7PHP ^7.1.3|^8.0

1.0.8PHP &gt;=7.1.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/3847a6da527c2873699314d5f6d010e4ab7146f9a68e543dd83c5b5afdc20128?d=identicon)[Venko007](/maintainers/Venko007)

---

Top Contributors

[![veneliniliev](https://avatars.githubusercontent.com/u/5311085?v=4)](https://github.com/veneliniliev "veneliniliev (43 commits)")[![andreiio](https://avatars.githubusercontent.com/u/1569300?v=4)](https://github.com/andreiio "andreiio (1 commits)")

---

Tags

fulltextlaravelmysqlsearchlaravelmysqlsearchablefulltext

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[kirschbaum-development/eloquent-power-joins

The Laravel magic applied to joins.

1.6k29.9M42](/packages/kirschbaum-development-eloquent-power-joins)[yajra/laravel-oci8

Oracle DB driver for Laravel via OCI8

8723.1M23](/packages/yajra-laravel-oci8)[glushkovds/phpclickhouse-laravel

Adapter of the most popular library https://github.com/smi2/phpClickHouse to Laravel

2051.4M2](/packages/glushkovds-phpclickhouse-laravel)[baril/sqlout

MySQL fulltext driver for Laravel Scout.

4513.6k](/packages/baril-sqlout)[itpathsolutions/dbstan

Database Standardization and Analysis Tool for Laravel

442.1k](/packages/itpathsolutions-dbstan)

PHPackages © 2026

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