Convert Figma logo to code with AI

laravel logoscout

Laravel Scout provides a driver based solution to searching your Eloquent models.

1,539
328
1,539
1

Top Related Projects

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

Pragmatically search through models and other sources

Quick Overview

Laravel Scout is an official Laravel package that provides a simple, driver-based solution for adding full-text search to Eloquent models. It offers a seamless integration with Laravel applications, allowing developers to easily implement powerful search functionality across their database records.

Pros

  • Easy integration with Laravel applications
  • Supports multiple search drivers (e.g., Algolia, MeiliSearch, Database)
  • Provides a clean and intuitive API for searching and indexing
  • Automatically syncs database changes with search indexes

Cons

  • Limited to Laravel framework
  • Some advanced search features may require additional configuration
  • Performance can vary depending on the chosen driver and data volume
  • May require additional services or infrastructure for certain drivers

Code Examples

  1. Marking a model as searchable:
use Laravel\Scout\Searchable;

class Post extends Model
{
    use Searchable;
}
  1. Performing a search:
$results = Post::search('Laravel')->get();
  1. Customizing the searchable data:
public function toSearchableArray()
{
    return [
        'title' => $this->title,
        'content' => $this->content,
        'author' => $this->author->name,
    ];
}
  1. Filtering search results:
$results = Post::search('Laravel')
    ->where('is_published', true)
    ->whereIn('category_id', [1, 2, 3])
    ->get();

Getting Started

  1. Install Laravel Scout via Composer:
composer require laravel/scout
  1. Publish the Scout configuration file:
php artisan vendor:publish --provider="Laravel\Scout\ScoutServiceProvider"
  1. Choose and configure a search driver in config/scout.php.

  2. Add the Searchable trait to your Eloquent models:

use Laravel\Scout\Searchable;

class Post extends Model
{
    use Searchable;
}
  1. Index your existing records:
php artisan scout:import "App\Models\Post"

Now you can use Scout's search methods in your application!

Competitor Comparisons

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

Pros of laravel-scout-tntsearch-driver

  • Provides a fast, lightweight, and self-contained full-text search engine
  • Supports advanced search features like fuzzy matching and boolean operators
  • Easy integration with Laravel Scout for local development and testing

Cons of laravel-scout-tntsearch-driver

  • Limited scalability for large datasets compared to more robust search engines
  • Requires more manual configuration and maintenance than some alternatives
  • May not be suitable for production environments with high-volume search requirements

Code Comparison

laravel-scout:

use Laravel\Scout\Searchable;

class Post extends Model
{
    use Searchable;
}

laravel-scout-tntsearch-driver:

use Laravel\Scout\Searchable;

class Post extends Model
{
    use Searchable;

    public function toSearchableArray()
    {
        return [
            'id' => $this->id,
            'title' => $this->title,
            'content' => $this->content,
        ];
    }
}

The main difference in code is that laravel-scout-tntsearch-driver often requires a more explicit toSearchableArray() method to define the searchable fields, while laravel-scout may use default model attributes if not specified. Both use the Searchable trait from Laravel Scout, maintaining a consistent API for search functionality.

Pragmatically search through models and other sources

Pros of Laravel Searchable

  • Lightweight and simple to set up, requiring minimal configuration
  • Works with any database or collection without additional drivers
  • Allows searching across multiple models in a single query

Cons of Laravel Searchable

  • Limited advanced search features compared to Scout's full-text search capabilities
  • No built-in support for external search engines or services
  • May not scale as well for large datasets or complex search requirements

Code Comparison

Scout:

use Laravel\Scout\Searchable;

class Post extends Model
{
    use Searchable;
}

Laravel Searchable:

use Spatie\Searchable\SearchResult;
use Spatie\Searchable\Searchable;

class Post extends Model implements Searchable
{
    public function getSearchResult(): SearchResult
    {
        // ...
    }
}

Scout offers a more straightforward implementation with the Searchable trait, while Laravel Searchable requires implementing an interface and defining a getSearchResult method.

Scout is better suited for projects requiring advanced search features or integration with external search services. Laravel Searchable is ideal for simpler search needs or when working with multiple models in a single search query. The choice between the two depends on the project's specific requirements and complexity.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Logo Laravel Scout

Build Status Total Downloads Latest Stable Version License

Introduction

Laravel Scout provides a simple, driver-based solution for adding full-text search to your Eloquent models. Once Scout is installed and configured, it will automatically sync your model changes to your search indexes. Currently, Scout supports:

Official Documentation

Documentation for Scout can be found on the Laravel website.

Contributing

Thank you for considering contributing to Scout! The contribution guide can be found in the Laravel documentation.

Code of Conduct

In order to ensure that the Laravel community is welcoming to all, please review and abide by the Code of Conduct.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

License

Laravel Scout is open-sourced software licensed under the MIT license.