PHPackages                             derworth/laravel-scout-mysql-driver - 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. derworth/laravel-scout-mysql-driver

ActiveLibrary

derworth/laravel-scout-mysql-driver
===================================

MySQL driver for Laravel Scout.

v4.0.2(4y ago)1401MITPHPPHP ^7.2|^8.0

Since Oct 10Pushed 4y agoCompare

[ Source](https://github.com/derworth/laravel-scout-mysql-driver)[ Packagist](https://packagist.org/packages/derworth/laravel-scout-mysql-driver)[ RSS](/packages/derworth-laravel-scout-mysql-driver/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (2)Dependencies (4)Versions (35)Used By (0)

Laravel Scout MySQL Driver
==========================

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

Search Eloquent Models using MySQL `FULLTEXT` Indexes or `WHERE LIKE '%:search%`' statements.

1. [Installation](#installation)
2. [Usage](#usage)
3. [Modes](#modes)
4. [Console Command](#console-command)
5. [Configuration](#configuration)

Installation

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

[](#installation-)

**Note: Any Models you plan to search using this driver must use a MySQL MyISAM or InnoDB table.**

If you haven't already you should [install Laravel Scout](https://laravel.com/docs/5.6/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 yab/laravel-scout-mysql-driver`

Next if you are using laravel version 5.4, include the following ServiceProvider to the Providers array in `config/app.php`

```
        /*
         * Package Service Providers...
         */
        Yab\MySQLScout\Providers\MySQLScoutServiceProvider::class,
```

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

```
    'mysql' => [
        'mode' => 'NATURAL_LANGUAGE',
        'model_directories' => [app_path()],
        'min_search_length' => 0,
        'min_fulltext_search_length' => 4,
        'min_fulltext_search_fallback' => 'LIKE',
        'query_expansion' => false
    ]
```

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

Please note this Laravel Scout driver does not need to update any indexes when a Model is changed as this is handled natively by MySQL. Therefore you can safely disable queuing in `config/scout.php`.

```
    /*
    |--------------------------------------------------------------------------
    | Queue Data Syncing
    |--------------------------------------------------------------------------
    |
    | This option allows you to control if the operations that sync your data
    | with your search engines are queued. When this is set to "true" then
    | all automatic data syncing will get queued for better performance.
    |
    */

    'queue' => false,
```

In addition there is no need to use the `php artisan scout:import` command. However, if you plan to use this driver in either `NATURAL_LANGUAGE` or `BOOLEAN` mode you should first run the provided [console command](#console-command) to create the needed `FULLTEXT` indexes.

Usage

--------

[](#usage-)

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

`$beers = App\Drink::search('beer')->get();`

Or With pagination:

`$beers = App\Drink::search('beer')->paginate(15);`

Simple constraints can be applied using the `where()` builder method (each additional `WHERE` will be applied using `AND`).

`$beers = App\Drink::search('beer')->where('in_stock', 1)->get();`

The following operators can be applied to the `WHERE` statements: ` != = = >`(`=` will be used if no operator is specified)

`$beers = App\Drink::search('beer')->where('abv >', 10)->get();`

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

Modes

--------

[](#modes-)

This driver can perform different types of search queries depending on the mode set in the `scout.mysql.mode`Laravel configuration value. Currently 4 different modes are supported `NATURAL_LANGUAGE`,`BOOLEAN`,`LIKE` and `LIKE_EXPANDED`.

### NATURAL\_LANGUAGE and BOOLEAN Modes

[](#natural_language-and-boolean-modes)

In `NATURAL_LANGUAGE` and `BOOLEAN` mode the driver will run MySQL `WHERE MATCH() AGAINST()` queries in the respective modes.

Both modes search queries will include all of Model's `FULLTEXT` compatible fields (`CHAR`,`VARCHAR`,`TEXT`) returned from the Model's `toSearchableArray()` method. It is required to have a `FULLTEXT` index for these fields. You can create this index using the provided [console command](#console-command).

For example running a search on a `POST` model with the following database structure:

column nametypeidint(10) UN AI PKcontentVARCHAR(255)metaTEXTwould produce the following query in `NATURAL_LANGUAGE` mode:

```
select * from `posts` where MATCH(content,meta) AGAINST(? IN NATURAL LANGUAGE MODE)
```

and the following query in `BOOLEAN` mode:

```
select * from `posts` where MATCH(content,meta) AGAINST(? IN BOOLEAN MODE)
```

Operators for `BOOLEAN` mode should be passed as part of the search string.

For more information see the [MySQL's Full-Text Search Functions documentation](http://dev.mysql.com/doc/refman/5.7/en/fulltext-search.html).

### LIKE and LIKE\_EXPANDED Modes

[](#like-and-like_expanded-modes)

`LIKE` and `LIKE_EXPANDED` modes will run `WHERE LIKE %?%` queries that will include all of the Model's fields returned from `toSearchableArray()`. `LIKE_EXPANDED` mode will query each field using each individual word in the search string.

For example running a search on a `Customer` model with the following database structure:

column nametypeidint(10) UN AI PKfirst\_nameVARCHAR(255)last\_nameVARCHAR(255)would produce the following query in `LIKE` mode given the search string "John":

```
SELECT * FROM `customers` WHERE (`id` LIKE '%John%' OR `first_name` LIKE '%John%' OR `last_name` LIKE '%JOHN%')
```

and the following query in `LIKE_EXPANDED` mode given the search string "John Smith":

```
SELECT * FROM `customers` WHERE (`id` LIKE '%John%' OR `id` LIKE '%Smith%' OR `first_name` LIKE '%John%' OR `first_name` LIKE '%Smith%' OR `last_name` LIKE '%John%' OR `last_name` LIKE '%Smith%')
```

Console Command

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

[](#console-command-)

The command `php artisan scout:mysql-index {model?}` is included to manage the `FULLTEXT` indexes needed for `NATURAL_LANGUAGE`and `BOOLEAN` modes.

If the model parameter is omitted the command will run with all Model's with the `Laravel\Scout\Searchable` trait and a MySQL connection within the directories defined in the `scout.mysql.model_directories` Laravel configuration value.

### Creating Indexes

[](#creating-indexes)

Pass the command a Model to create a `FULLTEXT` index for all of the Model's `FULLTEXT` compatible fields (`CHAR`,`VARCHAR`,`TEXT`) returned from the Model's `toSearchableArray()` method. The index name will be the result of the Model's `searchableAs()` method.

If an index already exists for the Model and the Model contains new searchable fields not in the existing index the index will be dropped and recreated.

`php artisan scout:mysql-index App\\Post`

### Dropping index

[](#dropping-index)

Pass the `-D` or `--drop` options to drop an existing index for a Model.

`php artisan scout:mysql-index App\\Post --drop`

Configuration

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

[](#configuration-)

Behavior can be changed by modifying the `scout.mysql` Laravel configuration values.

- `scout.mysql.mode` - The [mode](#mode) used to determine how the driver runs search queries. Acceptable values are `NATURAL_LANGUAGE`,`BOOLEAN`,`LIKE` and `LIKE_EXPANDED`.
- `scout.mysql.model_directories` - If no model parameter is provided to the included `php artisan scout:mysql-index`command the directories defined here will be searched for Model's with the `Laravel\Scout\Searchable` trait and a MySQL connection.
- `scout.mysql.min_search_length` - If the length of a search string is smaller then this value no search queries will run and an empty Collection will be returned.
- `scout.mysql.min_fulltext_search_length` - If using `NATURAL_LANGUAGE` or `BOOLEAN` modes and a search string's length is less than this value the driver will revert to a fallback mode. By default MySQL requires a search string length of at least 4 to to run `FULLTEXT` queries. For information on changing this see the [MySQL's Fine-Tuning MySQL Full-Text Search documentation](http://dev.mysql.com/doc/refman/5.7/en/fulltext-fine-tuning.html).
- `scout.mysql.min_fulltext_search_fallback` - The mode that will be used as a fallback when the search string's length is less than `scout.mysql.min_fulltext_search_length` in `NATURAL_LANGUAGE` or `BOOLEAN` modes. Acceptable values are `LIKE` and `LIKE_EXPANDED`.
- `scout.mysql.query_expansion` - If set to true MySQL query expansion will be used in search queries. Only applies if using `NATURAL_LANGUAGE` mode. For more information see [MySQL's Full-Text Searches with Query Expansion documentation](http://dev.mysql.com/doc/refman/5.7/en/fulltext-query-expansion.html).

###  Health Score

35

—

LowBetter than 79% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community20

Small or concentrated contributor base

Maturity80

Battle-tested with a long release history

 Bus Factor3

3 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 ~54 days

Recently: every ~168 days

Total

33

Last Release

1768d ago

Major Versions

v1.0.14 → v2.0.02017-07-30

v2.40 → v3.0.02020-03-11

v3.0.0 → v4.0.02021-04-16

PHP version history (4 changes)v1.0.0PHP &gt;=5.6.4

v2.1.0PHP &gt;=7.0

v3.0.0PHP &gt;=7.2

v4.0.0PHP ^7.2|^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/280a3709a24033f0c3c392b5f0c5e03b408244f5c3e937a4dfcbf7c446e9ded6?d=identicon)[derworth](/maintainers/derworth)

---

Top Contributors

[![msonowal](https://avatars.githubusercontent.com/u/6334484?v=4)](https://github.com/msonowal "msonowal (22 commits)")[![damiantw](https://avatars.githubusercontent.com/u/19997758?v=4)](https://github.com/damiantw "damiantw (16 commits)")[![hmazter](https://avatars.githubusercontent.com/u/805377?v=4)](https://github.com/hmazter "hmazter (6 commits)")[![namit-jindal](https://avatars.githubusercontent.com/u/48485567?v=4)](https://github.com/namit-jindal "namit-jindal (4 commits)")[![thekonz](https://avatars.githubusercontent.com/u/2700089?v=4)](https://github.com/thekonz "thekonz (4 commits)")[![romanmiranda](https://avatars.githubusercontent.com/u/5881720?v=4)](https://github.com/romanmiranda "romanmiranda (4 commits)")[![gkarugi](https://avatars.githubusercontent.com/u/17889563?v=4)](https://github.com/gkarugi "gkarugi (2 commits)")[![marky291](https://avatars.githubusercontent.com/u/5384515?v=4)](https://github.com/marky291 "marky291 (2 commits)")[![boboldehampsink](https://avatars.githubusercontent.com/u/378974?v=4)](https://github.com/boboldehampsink "boboldehampsink (2 commits)")[![mbardelmeijer](https://avatars.githubusercontent.com/u/1583095?v=4)](https://github.com/mbardelmeijer "mbardelmeijer (2 commits)")[![mlantz](https://avatars.githubusercontent.com/u/1065551?v=4)](https://github.com/mlantz "mlantz (2 commits)")[![antriver](https://avatars.githubusercontent.com/u/251159?v=4)](https://github.com/antriver "antriver (2 commits)")[![djekl](https://avatars.githubusercontent.com/u/1119714?v=4)](https://github.com/djekl "djekl (2 commits)")[![freezer278](https://avatars.githubusercontent.com/u/17979033?v=4)](https://github.com/freezer278 "freezer278 (2 commits)")[![tomlankhorst](https://avatars.githubusercontent.com/u/675432?v=4)](https://github.com/tomlankhorst "tomlankhorst (1 commits)")[![alpineglow](https://avatars.githubusercontent.com/u/81991357?v=4)](https://github.com/alpineglow "alpineglow (1 commits)")[![toonevdb](https://avatars.githubusercontent.com/u/2579951?v=4)](https://github.com/toonevdb "toonevdb (1 commits)")[![AustinW](https://avatars.githubusercontent.com/u/333398?v=4)](https://github.com/AustinW "AustinW (1 commits)")[![blaise-zaga](https://avatars.githubusercontent.com/u/3141704?v=4)](https://github.com/blaise-zaga "blaise-zaga (1 commits)")[![buchin](https://avatars.githubusercontent.com/u/156540?v=4)](https://github.com/buchin "buchin (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/derworth-laravel-scout-mysql-driver/health.svg)

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

###  Alternatives

[orchid/platform

Platform for back-office applications, admin panel or CMS your Laravel app.

4.8k2.5M59](/packages/orchid-platform)[teamtnt/laravel-scout-tntsearch-driver

Driver for Laravel Scout search package based on https://github.com/teamtnt/tntsearch

1.1k2.5M28](/packages/teamtnt-laravel-scout-tntsearch-driver)[algolia/scout-extended

Scout Extended extends Laravel Scout adding algolia-specific features

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

Search among multiple models with ElasticSearch and Laravel Scout

7431.6M2](/packages/matchish-laravel-scout-elasticsearch)[jeroen-g/explorer

Next-gen Elasticsearch driver for Laravel Scout.

397612.3k](/packages/jeroen-g-explorer)[sti3bas/laravel-scout-array-driver

Array driver for Laravel Scout

971.5M3](/packages/sti3bas-laravel-scout-array-driver)

PHPackages © 2026

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