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, vector search, 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:

Semantic and hybrid search (Meilisearch)

To use semantic or hybrid search with Meilisearch, configure an embedder in the index settings and embedding settings for each searchable model:
The model’s toSearchableEmbedding method may return source text, which Scout embeds using the Laravel AI SDK, or a precomputed embedding array. After updating the configuration, run scout:sync-index-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:

Embeddings

To enable semantic and hybrid search, define an embedding setting and vector field in the model’s Typesense configuration. By default, Scout uses the Laravel AI SDK to generate embeddings:
Your model’s toSearchableEmbedding method should return the source text that Scout should embed or a precomputed embedding array:
Typesense’s native embeddings can also be used without the Laravel AI SDK. See the Typesense documentation for details.

Turbopuffer

Turbopuffer is a search engine that supports full-text, semantic, and hybrid search. To use the Turbopuffer driver, set the SCOUT_DRIVER environment variable and provide your API key:
The TURBOPUFFER_REGION environment variable is optional and defaults to gcp-us-central1.

Turbopuffer configuration

Turbopuffer requires searchable attributes and a schema for each model. Define them in the model-settings array of your scout configuration:
The numeric values assigned to searchable-attributes are relative BM25 weights. To enable semantic search, add an embedding setting and vector schema:
Your model’s toSearchableEmbedding method should return source text for the Laravel AI SDK to embed or a precomputed embedding array. Alternatively, Turbopuffer’s native embeddings can be used without the AI SDK by setting the embedding driver to turbopuffer and including the source attribute in toSearchableArray.

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 database engine supports semantic and hybrid search when using PostgreSQL with the pgvector extension. Add a nullable vector column and a full-text index to the model’s table:
Define a toSearchableEmbedding method on the model to return source text or a precomputed embedding array. Scout stores embeddings in the embedding column by default; define searchableEmbeddingColumn to use another column. 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.
When using PostgreSQL, Scout can search a stored tsvector column to perform indexed, weighted full-text search. First, use the searchable method in a migration to add the generated search_vector column and its GIN index.
Column weights range from A (highest) to D (lowest). You can also pass a list of column names without weights, such as ['title', 'body'], in which case each column is assigned the default weight D. PostgreSQL automatically updates the generated column when the source columns change. Next, apply the SearchUsingFullText attribute to the model’s toSearchableArray method and set the vector option to true.
Only the column name is required. Scout searches the stored value directly. Return only the vector column, because adding LIKE clauses for other attributes may prevent PostgreSQL from using the GIN index. The searchable method also accepts a text search configuration, columns for a trigram index, and a custom vector column name.
To drop the generated column and its indexes when rolling back the migration, use the dropSearchable method with the same trigram columns and vector column name.

PostgreSQL search options

You can customize PostgreSQL full-text search with the second argument of the SearchUsingFullText attribute. plain mode searches for all query terms, and phrase mode matches when the terms appear in order. websearch mode supports web search syntax such as quoted phrases and excluded terms, and raw mode accepts PostgreSQL tsquery syntax. When searching a stored vector column, language must match the text search configuration used to generate the column. To enable typo tolerance, specify trigram columns in both the migration and the attribute options.
By default, Scout retries the search with trigram matching only when the initial search returns no results. Setting trigram_mode to blend includes trigram matches alongside full-text matches and factors trigram similarity into relevance ranking.
Trigram matching requires the pg_trgm extension to be available on the connection’s search path. When you specify trigram columns, the searchable migration method creates the extension, so the database user running the migration needs permission to create extensions.
For individual searches, you can override the mode, language, rank, trigram, and trigram_mode options with the options method.

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, Typesense, or Turbopuffer). 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:
The database, Meilisearch, Typesense, and Turbopuffer engines support semantic search, which matches records based on the meaning of a query. When Scout generates embeddings, semantic and hybrid searches require the Laravel AI SDK. Typesense’s native embeddings, Turbopuffer’s native embeddings, and precomputed query vectors do not require the Laravel AI SDK. After configuring embeddings for the selected engine, invoke the semantic method:
You may provide a minimum similarity threshold when supported by the selected engine:
To combine full-text and semantic search, use the hybrid method. Its arguments control the relative weights of text and semantic results:

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 November 11, 2026