babenkoivan / elastic-migrations

Elasticsearch migrations for Laravel
MIT License
189 stars 32 forks source link

ERROR: "Target [ElasticMigrations\IndexManagerInterface] is not instantiable" when running "php artisan elastic:migrate" command #10

Closed Mutahhar closed 4 years ago

Mutahhar commented 4 years ago

I've installed laravel/scout: 7.2.* babenkoivan/elastic-scout-driver: ^1.2 babenkoivan/elastic-scout-driver-plus: ^1.11 babenkoivan/elastic-migrations: ^1.2 in laravel 5.5.40

but when running php artisan elastic:migrate command after creatig elastic migration for users, it is giving an error

Target [ElasticMigrations\IndexManagerInterface] is not instantiable

can anyone help me fix it?

babenkoivan commented 4 years ago

Hey @Mutahhar, this package does not support Laravel 5. But I think the problem is that the old version of Laravel doesn't support package auto discovery feature, so you probably need to manually register ElasticClient\ServiceProvider and ElasticMigrations\ServiceProvider in configs/app.php.

Mutahhar commented 4 years ago

@babenkoivan I tried manually registering ElasticClient\ServiceProvider and ElasticMigrations\ServiceProvider but it did not work.

I will try again or will try to upgrade laravel.

Mutahhar commented 4 years ago

are your packages babenkoivan/elastic-scout-driver-plus and babenkoivan/elastic-scout-driver compatible with Laravel 6?

babenkoivan commented 4 years ago

@Mutahhar, yes they are

andrey-helldar commented 3 years ago

bootstrap/app.php:

$app->register(App\Providers\ScoutServiceProvider::class);
$app->register(Laravel\Scout\ScoutServiceProvider::class);
$app->register(ElasticClient\ServiceProvider::class);
$app->register(ElasticScoutDriver\ServiceProvider::class);
$app->register(ElasticMigrations\ServiceProvider::class);

When I call any artisan command, I get an error:

Target [ElasticMigrations\IndexManagerInterface] is not instantiable while building [ElasticMigrations\Console\FreshCommand].

Show logs
[2021-07-07 11:13:17] local.ERROR: Illuminate\Contracts\Container\BindingResolutionException: Target [ElasticMigrations\IndexManagerInterface] is not instantiable while building [ElasticMigrations\Console\FreshCommand]. in C:\dev\domains\crm\backend\vendor\illuminate\container\Container.php:978
Stack trace:
#0 C:\dev\domains\crm\backend\vendor\illuminate\container\Container.php(812): Illuminate\Container\Container->notInstantiable('ElasticMigratio...')
#1 C:\dev\domains\crm\backend\vendor\illuminate\container\Container.php(681): Illuminate\Container\Container->build('ElasticMigratio...')
#2 C:\dev\domains\crm\backend\vendor\illuminate\container\Container.php(629): Illuminate\Container\Container->resolve('ElasticMigratio...', Array)
#3 C:\dev\domains\crm\backend\vendor\laravel\lumen-framework\src\Application.php(274): Illuminate\Container\Container->make('ElasticMigratio...', Array)
#4 C:\dev\domains\crm\backend\vendor\illuminate\container\Container.php(945): Laravel\Lumen\Application->make('ElasticMigratio...')
#5 C:\dev\domains\crm\backend\vendor\illuminate\container\Container.php(873): Illuminate\Container\Container->resolveClass(Object(ReflectionParameter))
#6 C:\dev\domains\crm\backend\vendor\illuminate\container\Container.php(834): Illuminate\Container\Container->resolveDependencies(Array)
#7 C:\dev\domains\crm\backend\vendor\illuminate\container\Container.php(681): Illuminate\Container\Container->build('ElasticMigratio...')
#8 C:\dev\domains\crm\backend\vendor\illuminate\container\Container.php(629): Illuminate\Container\Container->resolve('ElasticMigratio...', Array)
#9 C:\dev\domains\crm\backend\vendor\laravel\lumen-framework\src\Application.php(274): Illuminate\Container\Container->make('ElasticMigratio...', Array)
#10 C:\dev\domains\crm\backend\vendor\illuminate\console\Application.php(261): Laravel\Lumen\Application->make('ElasticMigratio...')
#11 C:\dev\domains\crm\backend\vendor\illuminate\console\Application.php(275): Illuminate\Console\Application->resolve('ElasticMigratio...')
#12 C:\dev\domains\crm\backend\vendor\illuminate\support\ServiceProvider.php(312): Illuminate\Console\Application->resolveCommands(Array)
#13 C:\dev\domains\crm\backend\vendor\illuminate\console\Application.php(152): Illuminate\Support\ServiceProvider->Illuminate\Support\{closure}(Object(Illuminate\Console\Application))
#14 C:\dev\domains\crm\backend\vendor\illuminate\console\Application.php(75): Illuminate\Console\Application->bootstrap()
#15 C:\dev\domains\crm\backend\vendor\laravel\lumen-framework\src\Console\Kernel.php(208): Illuminate\Console\Application->__construct(Object(Laravel\Lumen\Application), Object(Illuminate\Events\Dispatcher), 'Lumen (6.3.3) (...')
#16 C:\dev\domains\crm\backend\vendor\laravel\lumen-framework\src\Console\Kernel.php(115): Laravel\Lumen\Console\Kernel->getArtisan()
#17 C:\dev\domains\crm\backend\artisan(35): Laravel\Lumen\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#18 {main} {"exception":"[object] (Illuminate\\Contracts\\Container\\BindingResolutionException(code: 0): Target [ElasticMigrations\\IndexManagerInterface] is not instantiable while building [ElasticMigrations\\Console\\FreshCommand]. at C:\\dev\\domains\\crm\\backend\\vendor\\illuminate\\container\\Container.php:978)
[stacktrace]
#0 C:\\dev\\domains\\crm\\backend\\vendor\\illuminate\\container\\Container.php(812): Illuminate\\Container\\Container->notInstantiable('ElasticMigratio...')
#1 C:\\dev\\domains\\crm\\backend\\vendor\\illuminate\\container\\Container.php(681): Illuminate\\Container\\Container->build('ElasticMigratio...')
#2 C:\\dev\\domains\\crm\\backend\\vendor\\illuminate\\container\\Container.php(629): Illuminate\\Container\\Container->resolve('ElasticMigratio...', Array)
#3 C:\\dev\\domains\\crm\\backend\\vendor\\laravel\\lumen-framework\\src\\Application.php(274): Illuminate\\Container\\Container->make('ElasticMigratio...', Array)
#4 C:\\dev\\domains\\crm\\backend\\vendor\\illuminate\\container\\Container.php(945): Laravel\\Lumen\\Application->make('ElasticMigratio...')
#5 C:\\dev\\domains\\crm\\backend\\vendor\\illuminate\\container\\Container.php(873): Illuminate\\Container\\Container->resolveClass(Object(ReflectionParameter))
#6 C:\\dev\\domains\\crm\\backend\\vendor\\illuminate\\container\\Container.php(834): Illuminate\\Container\\Container->resolveDependencies(Array)
#7 C:\\dev\\domains\\crm\\backend\\vendor\\illuminate\\container\\Container.php(681): Illuminate\\Container\\Container->build('ElasticMigratio...')
#8 C:\\dev\\domains\\crm\\backend\\vendor\\illuminate\\container\\Container.php(629): Illuminate\\Container\\Container->resolve('ElasticMigratio...', Array)
#9 C:\\dev\\domains\\crm\\backend\\vendor\\laravel\\lumen-framework\\src\\Application.php(274): Illuminate\\Container\\Container->make('ElasticMigratio...', Array)
#10 C:\\dev\\domains\\crm\\backend\\vendor\\illuminate\\console\\Application.php(261): Laravel\\Lumen\\Application->make('ElasticMigratio...')
#11 C:\\dev\\domains\\crm\\backend\\vendor\\illuminate\\console\\Application.php(275): Illuminate\\Console\\Application->resolve('ElasticMigratio...')
#12 C:\\dev\\domains\\crm\\backend\\vendor\\illuminate\\support\\ServiceProvider.php(312): Illuminate\\Console\\Application->resolveCommands(Array)
#13 C:\\dev\\domains\\crm\\backend\\vendor\\illuminate\\console\\Application.php(152): Illuminate\\Support\\ServiceProvider->Illuminate\\Support\\{closure}(Object(Illuminate\\Console\\Application))
#14 C:\\dev\\domains\\crm\\backend\\vendor\\illuminate\\console\\Application.php(75): Illuminate\\Console\\Application->bootstrap()
#15 C:\\dev\\domains\\crm\\backend\\vendor\\laravel\\lumen-framework\\src\\Console\\Kernel.php(208): Illuminate\\Console\\Application->__construct(Object(Laravel\\Lumen\\Application), Object(Illuminate\\Events\\Dispatcher), 'Lumen (6.3.3) (...')
#16 C:\\dev\\domains\\crm\\backend\\vendor\\laravel\\lumen-framework\\src\\Console\\Kernel.php(115): Laravel\\Lumen\\Console\\Kernel->getArtisan()
#17 C:\\dev\\domains\\crm\\backend\\artisan(35): Laravel\\Lumen\\Console\\Kernel->handle(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#18 {main}
"} 

UPD: Solved!

Step 1: just read a https://github.com/babenkoivan/elastic-migrations/wiki/Lumen-Installation 😀

Step 2: add a new code in my service provider:

Show ScoutServiceProvider ```php namespace App\Providers; use ElasticMigrations\ServiceProvider as MigrationsServiceProvider; use ElasticScoutDriver\ServiceProvider; use Illuminate\Support\ServiceProvider as BaseServiceProvider; final class ScoutServiceProvider extends BaseServiceProvider { public function boot() { $this->bootDriver(); } protected function bootDriver(): void { $this->bootBindings(ServiceProvider::class); $this->bootBindings(MigrationsServiceProvider::class); } protected function bootBindings(string $class) { foreach ($this->bindings($class) as $abstract => $concrete) { $this->app->bind($abstract, $concrete); } } protected function bindings(string $class): array { $provider = new $class($this->app); return $provider->bindings; } } ```

image