Skip to main content

Introduction

Laravel Scout provides a simple, driver-based solution for adding full-text search to your Eloquent models. Using model observers, Scout will automatically keep your search indexes in sync with your Eloquent records. Scout ships with a built-in database engine that uses MySQL / PostgreSQL full-text indexes and LIKE clauses to search your existing database — no external service required. For large-scale production workloads requiring typo tolerance, faceted filtering, or geo-search, external engines are available.

Supported engines

Installation

Install Scout via Composer:
After installing, publish the Scout configuration file. This command publishes scout.php to your application’s config directory:
Finally, add the Laravel\Scout\Searchable trait to the model you want to make searchable. This trait registers a model observer that keeps the model in sync with your search driver:

Queueing

When using an engine other than database or collection, you should strongly consider configuring a queue driver before using Scout. Running a queue worker allows Scout to queue all index sync operations in the background, providing much better response times for your web interface. Set the queue option in config/scout.php to true:
You can also specify the connection and queue name:
Then run a queue worker for the dedicated queue:

Unique indexing jobs

In write-heavy applications, you may wish to prevent Scout from queueing duplicate jobs for the same model records. You may opt into unique indexing jobs by registering the MakeSearchableUniquely and RemoveFromSearchUniquely job classes, typically within the boot method of a service provider:
These jobs use Laravel’s unique job locks to avoid dispatching duplicate queued indexing operations for the same searchable model records while a matching job is already queued.

Driver prerequisites

Algolia

When using the Algolia driver, configure your id and secret credentials in config/scout.php and install the Algolia PHP SDK:
Add your credentials to the .env file:

Index settings

You can manage Algolia index settings directly in config/scout.php:
After configuring, sync the settings to Algolia:

Meilisearch

Meilisearch is a fast, open source search engine. For local development, the easiest way is to use Laravel Sail’s Docker environment.
Without Sail, you can start Meilisearch directly with Docker:
Install the Meilisearch PHP SDK:
Set the driver and host in your .env file:
When upgrading Scout on an application that uses Meilisearch, always review any breaking changes to the Meilisearch service itself.

Index settings (Meilisearch)

Meilisearch requires you to pre-define filterableAttributes for columns you plan to use with Scout’s where method, and sortableAttributes for columns you plan to sort by:
Pay attention to data types — Meilisearch only performs filter operations (>, <, etc.) on data of the correct type:
After configuring, sync the settings:

Typesense

Typesense is a lightning-fast, open source search engine with support for keyword, semantic, geo, and vector search.
Set the connection details in your .env file:
When using Typesense, your toSearchableArray method must cast the model’s primary key to a string and creation date to a UNIX timestamp:

Database / collection engines

These built-in engines require no external service. The database engine uses MySQL / PostgreSQL full-text indexes and LIKE clauses. It is the recommended starting point for most applications:
The collection engine retrieves all records from your database and filters them in PHP, so it works with any database Laravel supports, including SQLite. It is intended for local development, small datasets, and tests:
The database engine searches your database tables directly — no separate indexing step is required.

The Searchable trait

Customizing toSearchableArray()

By default, the entire toArray form of a model is persisted to its search index. Override toSearchableArray to control which data is synchronized:

Customizing the index name

By default, the model’s table name (plural) is used as the index name. Override searchableAs to customize it:

Database engine search strategies

For the database engine, you can assign PHP attributes to specify more efficient per-column search strategies:
Before using SearchUsingFullText, ensure the column has a full-text index.

Conditionally searchable models

To make a model searchable only under certain conditions, define a shouldBeSearchable method:
shouldBeSearchable is not applicable when using the database engine. Use where clauses instead.

Index management

The commands in this section are primarily relevant when using a third-party engine (Algolia, Meilisearch, or Typesense). The database engine does not require manual index management.

Batch import

If you are adding Scout to an existing project, import existing database records into your indexes:
To import using queued jobs in the background:

Flushing the index

Remove all records for a model from its search index:

Pausing indexing

To perform a batch of Eloquent operations without syncing to the search index, use withoutSyncingToSearch:

Manually adding and removing records

Add a collection of models to the index via an Eloquent query:
Remove records from the index using unsearchable:
Deleting a model removes it from the search index automatically.

Searching

Use the search method to search a model. Chain get to retrieve the matching Eloquent models:
You can return search results directly from a route or controller — they will be converted to JSON automatically:
To get the raw search results before they are converted to Eloquent models, use raw:

Pagination

Paginate search results with the paginate method, which returns an Illuminate\Pagination\LengthAwarePaginator:
The database engine also supports simplePaginate, which skips the total count query for better performance on large datasets:
Render results and pagination links in a Blade template:

Filtering and sorting

Add filter conditions to your search query with where:
When using Meilisearch, you must configure filterable attributes before using Scout’s where clauses.
Customize the Eloquent query for the results using query:

Eager loading

Scout retrieves IDs from the search engine and then fetches the models via Eloquent. To avoid N+1 queries, use the query method to eager load relationships:
To eager load relationships during batch import, define makeAllSearchableUsing on the model:
makeAllSearchableUsing may not be applicable when using a queue to batch import models, because relationships are not restored when model collections are processed by jobs.

Soft deleting

If your indexed models use soft deletes and you need to search soft deleted records, set soft_delete to true in config/scout.php:
You can then use withTrashed or onlyTrashed when searching:

Custom engines

If the built-in engines don’t meet your needs, you can write your own. Extend the Laravel\Scout\Engines\Engine abstract class and implement its eight required methods:
Review Laravel\Scout\Engines\AlgoliaEngine for a reference implementation. Register your custom engine in the boot method of App\Providers\AppServiceProvider:
Then specify it as the driver in config/scout.php:

Eloquent ORM

Learn the fundamentals of working with Eloquent models.

Eloquent relationships

Learn how to define relationships and use eager loading.

Queues

Scout can use queues to update indexes in the background.
Last modified on July 20, 2026