cfpinto / laravel-scout-elasticsearch
Laravel scout driver for ElasticSearch
Requires
- php: >=7.1.0
- ext-json: *
- elasticsearch/elasticsearch: ^6.0
- laravel/scout: ^7.0
Requires (Dev)
- fzaninotto/faker: ^1.8
- mockery/mockery: ^1.2
- phpunit/phpunit: ^7.4
README
Disclaimer: This project was highly inspired in ErickTamayo implementation. However it is not a fork and most likely is incompatible.
This package is intented to be used with laravel 5.6 and up. Others versions might work but might
Installation
composer require cfpinto/laravel-scout-elasticsearch
If your project doesn't have auto discovery you will need to add the providers manually in your app.php config file
'providers' => [ ... Laravel\Scout\ScoutServiceProvider::class, ... ScoutEngines\Elasticsearch\ElasticsearchProvider::class ],
Setup Elasticsearch configuration
You must have an Elasticsearch instance running with the necessary index.
Change the config/scout.php file to include elasticsearch settings
// config/scout.php // Set your driver to elasticsearch 'driver' => env('SCOUT_DRIVER', 'elasticsearch'), ... 'elasticsearch' => [ 'index' => env('ELASTICSEARCH_INDEX', 'laravel'), 'hosts' => [ env('ELASTICSEARCH_HOST', 'http://localhost'), ], ], ...
Usage
The driver will work just like described in laravel scout documentation.
If you want the ability to use closures in where and orWhere methods your model must use the Searchable trait included in the package
<?php namespace App; use ScoutEngines\Elasticsearch\Traits\Searchable; class Product extends Model { use Searchable; }
Credits
Support on Beerpay
Hey dude! Help me out for a couple of 🍻!