laravel安装laravel-scout-elastic、laravel/scout

王俊楚
2023-12-01

安装elasticsearch-rtf,github上下载安装即可,前提必须安装java包。

接下来安装laravel扩展Scout、Scout-elastic

首先,我们通过 Composer 包管理器来安装 Scout:

composer require laravel/scout

接下来,需要添加 ScoutServiceProvider 到配置文件 config/app.phpproviders 数组:

Laravel\Scout\ScoutServiceProvider::class,

注册 Scout 服务提供者之后,还需要通过 Artisan 命令 vendor:publish 发布Scout 配置,该命令会发布配置文件 scout.phpconfig 目录:

php artisan vendor:publish --provider="Laravel\Scout\ScoutServiceProvider"


Installation

You can install the package via composer:

composer require tamayo/laravel-scout-elastic

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,
    ...
    ScoutEngines\Elasticsearch\ElasticsearchProvider::class,
],

Setting up Elasticsearch configuration

You must have a Elasticsearch server up and running with the index you want to use created

If you need help with this please refer to the Elasticsearch documentation

After you've published the Laravel Scout package configuration:

// 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'),
        ],
    ],
...
 类似资料: