Skip to content

globalia/laravel-scout-mysql

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Laravel Scout MySQL Driver

This package is a MySQL driver for Laravel Scout.

Contents

Installation

You can install the package via composer:

composer config repositories.globalia/laravel-scout-mysql git https://github.com/globalia/laravel-scout-mysql.git

composer require "globalia/laravel-scout-mysql" "^1.0"

You must add the Scout service provider and the package service provider in your app.php config:

// config/app.php
'providers' => [
    ...
    Laravel\Scout\ScoutServiceProvider::class,
    Globalia\LaravelScoutMysql\ScoutMysqlServiceProvider::class,
],

Setting up database search indexes table:

php artisan migrate

After you've published the Laravel Scout package configuration:

// config/scout.php
// Set your driver to mysql
    'driver' => env('SCOUT_DRIVER', 'mysql'),

Usage

Here is an example of how to use the engine:

    $result = Todo::search($term)
        ->where('boost(name)', 5)
        ->where('boost(tags)', 2)
        ->where('checked', 1)
        ->where('published_at >=', \Carbon::now());

    return null === $limit ? $result->get() : $result->paginate($limit);

Instead of using the "Laravel\Scout\Searchable" trait, use this "Globalia\LaravelScoutMysql\Models\Concerns\HasSearchIndex"

otherwise you can use Laravel Scout as described in the official documentation

Searching in all models

Since the index table is a model, you can search in it directly. Each result will be hydrated to its corresponding model.

    $result = SearchIndex::search($term);

Credits