Answer the question
In order to leave comments, you need to log in
Unresolvable dependency resolving [Parameter #0 [ $retries ]] in class Elasticsearch\Transport?
Laravel 4.2 -> Created an ElasticServiceProvider
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Elasticsearch\Client;
use Elasticsearch\ClientBuilder;
class ElasticServiceProvider extends ServiceProvider
{
public function register()
{
$this->app->bind(Elastic::class, function ($app) {
return new Elastic(
ClientBuilder::create()
->setLogger(ClientBuilder::defaultLogger(storage_path('logs/elastic.log')))
->build()
);
});
$this->app->bind(Client::class, function () {
return ClientBuilder::create()->build();
});
}
}
namespace App\Elastic;
use Elasticsearch\Client;
class Elastic
{
protected $client;
public function __construct(Client $client)
{
$this->client = $client;
}
public function search(array $parameters)
{
return $this->client->search($parameters);
}
}
public function searchUser()
{
$elastic = app(App\Elastic\Elastic::class);
dd($elastic);
lluminate \ Container \ BindingResolutionException
Unresolvable dependency resolving [Parameter #0 [ <required> $retries ]] in class Elasticsearch\Transport
<?php
use Elasticsearch\Client;
use Elasticsearch\ClientBuilder;
use Illuminate\Support\ServiceProvider;
use Illuminate\Foundation\Application as Apy;
class HomeController extends BaseController
{
protected $client;
protected $app;
public function __construct(Client $client, Apy $app)
{
$this->client = $client;
$this->app = $app;
}
public function searchUser()
{
App::bind('foo', function($app)
{
return new User;
});
$value = App::make('foo');
dd($value);
Answer the question
In order to leave comments, you need to log in
There were a lot of bugs, one of which is that the Elasticsearch version should be ~1.0 for Laravel 4.2 .
+ you need to install JVM
+ install Elastic via console
+ composer.json file... classmap": [ .... , you need to add new folders with classes and enter composer dumpautoload (in my case)
"autoload": {
"classmap": [
"app/Observers",
"app/Providers",
"app/Services",
public function saved($model)
{
$this->client->index([
'index' => 'lara_users',
'type' => 'user',
'id' => $model->id,
'body' => $model->toArray()
]);
}
// User class
public static function boot()
{
parent::boot();
$client = App::make(Elasticsearch\Client::class);
self::observe(new App\Observers\UserObserver($client));
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question