---
title: "Laravel 12: How to Build Advanced Search with Laravel Scout"
url: "https://magecomp.com/blog/advanced-search-with-laravel-scout/"
date: "2026-05-27T11:24:45+00:00"
modified: "2026-05-27T11:24:47+00:00"
author:
  name: "Bharat Desai"
  url: "https://magecomp.com"
categories:
  - "Laravel"
word_count: 832
reading_time: "5 min read"
summary: "In today's world, it is necessary that an application has the facility of quick and smart search in order to offer an optimal experience. This is because whatever type of website you develop, wheth..."
description: "Build advanced full-text search in Laravel 12 using Laravel Scout"
keywords: "Laravel"
language: "en"
schema_type: "Article"
related_posts:
  - title: "How to Use Soft Delete in Laravel 8?"
    url: "https://magecomp.com/blog/soft-delete-laravel-8/"
  - title: "Generating Thumbnails with Spatie Media Library in Laravel 11: A Step-by-Step Guide"
    url: "https://magecomp.com/blog/generating-thumbnails-with-spatie-media-library-laravel-11/"
  - title: "How to Send Database and Email Notifications in Laravel?"
    url: "https://magecomp.com/blog/send-database-and-email-notifications-laravel/"
---

# Laravel 12: How to Build Advanced Search with Laravel Scout

_Published: May 27, 2026_  
_Author: Bharat Desai_  

![Laravel 12 How to Build Advanced Search with Laravel Scout](https://magecomp.com/blog/wp-content/uploads/2026/05/Laravel-12-How-to-Build-Advanced-Search-with-Laravel-Scout-1024x512.webp)

In today’s world, it is necessary that an application has the facility of quick and smart search in order to offer an optimal experience. This is because whatever type of website you develop, whether it is an e-commerce website, blogging platform, CRM, SaaS, etc., it must have the ability to display live search results and precise results.

By using Laravel Scout, implementing full-text search capabilities in your Laravel application has never been easier. It supports Laravel 12, which means you can now implement a simple yet powerful way to build advanced search engines using drivers of Algolia, Meilisearch, Typesense, and a database.

[![Laravel Development Services](https://magecomp.com/blog/wp-content/uploads/2024/12/Laravel-Development-Services-3-1024x284.webp)](https://magecomp.com/services/laravel-development-services/)In this blog post, we’ll show you how to implement an advanced searching feature using the Laravel Scout package in Laravel version 12.

## Prerequisite:
1. Composer (latest Version)

2. Laravel version 12

## Steps to Build Advanced Search with Laravel Scout:
Here are the steps to follow:

Step 1: Install Laravel 12

Step 2: Set Database Configuration and Migration

Step 3: Install Laravel Scout

Step 4: Create Model and Migration

Step 5: Configure Searchable Model

Step 6: Create Routes

Step 7: Create Controller

Step 8: Create Blade File

Step 9: Test Project

Now, let’s see all the steps with the detailed information.

### Step 1: Install Laravel 12
For this demo, we need a new project. Create it using the following command:

```
composer create-project laravel/laravel:^12.0 scout-search-demo
```

### Step 2: Set Database details and migrate
Set your database details in .env to your current database credentials, then run the following command to migrate your database.

```
php artisan migrate
```

Publish the Scout configuration file.

```
php artisan vendor:publish --provider="LaravelScoutScoutServiceProvider"
```

### Step 3: Install Laravel Scout
Next, install the Laravel Scout package via the command shown below.

```
composer require laravel/scout
```

Set Scout driver in .env file

```
SCOUT_DRIVER=database
```

### Step 4: Create Model and Migration
Next, create a Product model with migration.

```
php artisan make:model Product -m
```

Update migration file:

**database/migrations/create_products_table.php**

```
<?php
use IlluminateDatabaseMigrationsMigration;
use IlluminateDatabaseSchemaBlueprint;
use IlluminateSupportFacadesSchema;
return new class extends Migration
{
    public function up(): void
    {
        Schema::create('products', function (Blueprint $table) {
            $table->id();
            $table->string('name');
            $table->text('description')->nullable();
            $table->integer('price');
            $table->timestamps();
        });
    }
    public function down(): void
    {
        Schema::dropIfExists('products');
    }
};
```

### Step 5: Configure Searchable Model
Next, update the Product model by adding the searchable attribute to it.

**app/Models/Product.php**

```
<?php

namespace AppModels;

use IlluminateDatabaseEloquentModel;
use LaravelScoutSearchable;

class Product extends Model
{
    use Searchable;

    protected $fillable = [
        'name',
        'description',
        'price'
    ];

    /**
     * Get searchable array for the model
     */
    public function toSearchableArray(): array
    {
        return [
            'name' => $this->name,
            'description' => $this->description,
        ];
    }
}
```

### Step 6: Create Routes
Next, create routes for product searches.

**routes/web.php**

```
<?php
use IlluminateSupportFacadesRoute;
use AppHttpControllersProductController;
Route::get('/', [ProductController::class, 'index']);
```

### Step 7: Create Controller
Next, we will create the ProductController using the command below.

```
php artisan make:controller ProductController
```

**app/Http/Controllers/ProductController.php**

```
<?php

namespace AppHttpControllers;

use IlluminateHttpRequest;
use AppModelsProduct;

class ProductController extends Controller
{
    /**
     * Display products with search
     */
    public function index(Request $request)
    {
        $search = $request->search;

        if ($search) {
            $products = Product::search($search)->get();
        } else {
            $products = Product::latest()->get();
        }

        return view('products', compact('products'));
    }
}
```

### Step 8: Create Blade File
Next, create a blade file.

**resources/views/products.blade.php**

```

<html>
<head>
    <title>Laravel Scout Search</title>
</head>
<body>

<h2>Advanced Product Search</h2>

<form method="GET" action="/">
    <input type="text" name="search" placeholder="Search Products">
    <button type="submit">Search</button>
</form>

<br>

<table border="1" cellpadding="10">
    <tr>
        <th>ID</th>
        <th>Name</th>
        <th>Description</th>
        <th>Price</th>
    </tr>

    @foreach($products as $product)
    <tr>
        <td>{{ $product->id }}</td>
        <td>{{ $product->name }}</td>
        <td>{{ $product->description }}</td>
        <td>{{ $product->price }}</td>
    </tr>
    @endforeach

</table>

</body>
</html>
```

### Step 9: Test Project
Finally, test the project by executing the code below.

```
php artisan serve
```

Now, navigate to your web browser, input the provided URL, and check the project’s output:

http://localhost:8000/

Finally, use the search input field to search for the products, and Laravel Scout will display matching records from the database.

## Conclusion
Using Laravel Scout, you can easily add search functionalities to your Laravel 12 applications and make use of an advanced search capability by integrating Meilisearch to ensure speedy filtering, ordering, pagination, and indexing of search results.

No matter whether you develop an eCommerce website, blog, or any other kind of application, Laravel Scout provides efficient and effective search functionalities with ease.

[![Hire Laravel Expert Now](https://magecomp.com/blog/wp-content/uploads/2024/12/Hire-Laravel-Expert-Now-1024x284.webp)](https://magecomp.com/services/hire-laravel-developer/)

## FAQ
**1. What is Laravel Scout?**

Laravel Scout is a Laravel package having full-text search capability for Eloquent Models.

**2. Which Search Engines Does Laravel Scout Work With?**

Laravel Scout supports:

- Meilisearch
- Algolia
- Typesense
- Database driver

**3. Does Laravel Scout support large datasets?**

Yes, Laravel Scout is very effective in handling large data sets efficiently due to external search engine support.

</body></html>


---

_View the original post at: [https://magecomp.com/blog/advanced-search-with-laravel-scout/](https://magecomp.com/blog/advanced-search-with-laravel-scout/)_  
_Served as markdown by [Third Audience](https://github.com/third-audience) v3.5.3_  
_Generated: 2026-05-27 11:24:48 UTC_  
