Php 在Laravel中未找到弹性类
我在Laravel项目中安装弹性搜索时遇到问题。我犯了一个错误 未找到类“Elastica\Client” 当我尝试使用VisualStudio选项导入类时,会收到“找不到类”通知。我通过composer安装了elasticsearch,方法是添加Php 在Laravel中未找到弹性类,php,laravel,
elasticsearch,Php,Laravel,
elasticsearch,我在Laravel项目中安装弹性搜索时遇到问题。我犯了一个错误 未找到类“Elastica\Client” 当我尝试使用VisualStudio选项导入类时,会收到“找不到类”通知。我通过composer安装了elasticsearch,方法是添加composer.json文件elasticsearch,然后输入composer update,然后在app/config.php文件中添加classed并运行composer dump autoload。当我在测试页面上进入我的站点时,我得到了那个
composer.json
文件elasticsearch,然后输入composer update
,然后在app/config.php
文件中添加classed并运行composer dump autoload
。当我在测试页面上进入我的站点时,我得到了那个错误。还要提到的是,我使用了最新版本的laravel
、php
和mysql
。感谢您的帮助。这是我的密码
CategoryController.php
<?php
namespace App\Http\Controllers;
use App\User;
use App\Category;
use App\Property;
use Illuminate\Http\Request;
use Elasticsearch\ClientBuilder;
use Elastica\Client as ElasticaClient;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Cookie;
class CategoryController extends Controller
{
protected $elasticSearch;
protected $elastica;
public function __construct()
{
$this->elasticSearch = ClientBuilder::create()->build();
$elasticaConfig = [
'host' => 'localhost',
'port' => 9200,
'index' => 'pets'
];
$this->elastica = new ElasticaClient($elasticaConfig);
// Here is error!!!
}
public function elasticSearchTest()
{
dump($this->elasticSearch);
echo "\n\nRetrieve a document:\n";
$params = [
'index' => 'real-estate-laravel',
'type' => 'properties',
'id' => '1'
];
$response = $this->elasticSearch->get($params);
dump($response);
}
}
'providers' => [
Elasticquent\ElasticquentServiceProvider::class,
],
'aliases' => [
'Es' => Elasticquent\ElasticquentElasticsearchFacade::class,
],
composer.json
"require": {
"php": "^7.1.3",
"doctrine/dbal": "^2.9",
"fideloper/proxy": "^4.0",
"jorenvanhocht/laravel-share": "^2.0",
"laravel/framework": "5.8.*",
"laravel/socialite": "^4.1",
"laravel/tinker": "^1.0",
"mews/captcha": "^2.2",
"predis/predis": "^1.1",
"zizaco/entrust": "5.2.x-dev",
"elasticquent/elasticquent": "dev-master"
},
web.php
Route::prefix('elasticsearch')->group(function () {
Route::get('/', 'CategoryController@index')->name('startpage');
Route::get('/search', 'CategoryController@search')->name('search.param');
Route::get('test', ['uses' => 'CategoryController@elasticSearchTest']);
});
尝试安装
composer
而不是composer update
,因为composer update
会更新整个应用程序的依赖项的较新版本。@techguru就是这么做的。相同的错误导航到您的供应商路径,并检查包是否存在或存在not@AshrafHefny它们存在你用的是哪种型号的橡皮筋?