Answer the question
In order to leave comments, you need to log in
Class App\Elastic\Elastic does not exist when it clearly exists?
Laravel 4.2, in Illuminate\Support\ServiceProvider
public function boot() {
$elastic = $this->app->make(\App\Elastic\Elastic::class);
Post::saved(function ($post) use ($elastic) {
$elastic->index([
'index' => 'blog',
'type' => 'post',
'id' => $post->id,
'body' => $post->toArray()
]);
});
}
namespace App\Elastic;
use Elasticsearch\Client;
class Elastic
{....
<?php
namespace App\Elastic;
use Illuminate\Support\ServiceProvider;
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()
);
});
}
}
public function searchUser()
{
$elastic = app(Elastic::class);
"autoload": {
"classmap": [
"app/commands",
"app/controllers",
"app/Elastic",
"app/models",
"app/database/migrations",
"app/database/seeds",
"app/tests/TestCase.php"
]
composer dumpautoload
and to no avail, the class is still not found when it is clearly there. Well, I threw the class back into the models folder iiii, now it gives an error that the class already exists .... omg. public function searchUser()
{
$elastic = app()->make(App\Services\Elastic::class);
dd($elastic);
Illuminate \ Container \ BindingResolutionException
Unresolvable dependency resolving [Parameter #0 [ <required> $retries ]] in class Elasticsearch\Transport
<?php
namespace App\Providers;
use Elasticsearch\Client;
use Elasticsearch\ClientBuilder;
use Illuminate\Support\ServiceProvider;
use Illuminate\Foundation\Application as App;
class AppServiceProvider extends ServiceProvider
{
protected $app;
public function __construct(App $app)
{
$this->app = $app;
}
public function register()
{ // пробовал и Elastic::class / Client::class
$this->app->bind(\App\Services\Elastic::class, function () {
return \Elasticsearch\ClientBuilder::create()->build();
});
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question