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-indatabase 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:scout.php to your application’s config directory:
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 thandatabase 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:
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 theMakeSearchableUniquely and RemoveFromSearchUniquely job classes, typically within the boot method of a service provider:
Driver prerequisites
Algolia
When using the Algolia driver, configure yourid and secret credentials in config/scout.php and install the Algolia PHP SDK:
.env file:
Index settings
You can manage Algolia index settings directly inconfig/scout.php:
Meilisearch
Meilisearch is a fast, open source search engine. For local development, the easiest way is to use Laravel Sail’s Docker environment..env file:
Index settings (Meilisearch)
Meilisearch requires you to pre-definefilterableAttributes for columns you plan to use with Scout’s where method, and sortableAttributes for columns you plan to sort by:
>, <, etc.) on data of the correct type:
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: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..env file:
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 anembedding setting and vector field in the model’s Typesense configuration. By default, Scout uses the Laravel AI SDK to generate embeddings:
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 theSCOUT_DRIVER environment variable and provide your API key:
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 themodel-settings array of your scout configuration:
searchable-attributes are relative BM25 weights. To enable semantic search, add an embedding setting and vector schema:
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 andLIKE clauses. It is the recommended starting point for most applications:
Semantic and hybrid search
The database engine supports semantic and hybrid search when using PostgreSQL with thepgvector extension. Add a nullable vector column and a full-text index to the model’s table:
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 entiretoArray 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. OverridesearchableAs to customize it:
Database engine search strategies
For the database engine, you can assign PHP attributes to specify more efficient per-column search strategies:Conditionally searchable models
To make a model searchable only under certain conditions, define ashouldBeSearchable method:
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: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, usewithoutSyncingToSearch:
Manually adding and removing records
Add a collection of models to the index via an Eloquent query:unsearchable:
Searching
Use thesearch method to search a model. Chain get to retrieve the matching Eloquent models:
raw:
Semantic search
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 thesemantic method:
hybrid method. Its arguments control the relative weights of text and semantic results:
Pagination
Paginate search results with thepaginate method, which returns an Illuminate\Pagination\LengthAwarePaginator:
simplePaginate, which skips the total count query for better performance on large datasets:
Filtering and sorting
Add filter conditions to your search query withwhere:
query:
Eager loading
Scout retrieves IDs from the search engine and then fetches the models via Eloquent. To avoid N+1 queries, use thequery method to eager load relationships:
makeAllSearchableUsing on the model:
Soft deleting
If your indexed models use soft deletes and you need to search soft deleted records, setsoft_delete to true in config/scout.php:
withTrashed or onlyTrashed when searching:
Custom engines
If the built-in engines don’t meet your needs, you can write your own. Extend theLaravel\Scout\Engines\Engine abstract class and implement its eight required methods:
Laravel\Scout\Engines\AlgoliaEngine for a reference implementation.
Register your custom engine in the boot method of App\Providers\AppServiceProvider:
config/scout.php:
Related pages
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.