0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Target [App\Xxx\Yyy\ZzzInterface] is not instantiable. エラーが出た時の対処法

Last updated at Posted at 2023-06-25

エラーメッセージ

Target [App\Xxx\Yyy\ZzzInterface] is not instantiable.

ScreenShot 2023-06-25 18.29.21.png

問題のコード

app/Providers/AppServiceProvider.php
<?php

declare(strict_types=1);

namespace App\Providers;

use App\Aws\CognitoIdentityProvider\AdminCreateUser\AdminCreateUser;
use App\Aws\CognitoIdentityProvider\AdminCreateUser\AwsAdminCreateUser;
use Illuminate\Contracts\Support\DeferrableProvider;
use Illuminate\Support\ServiceProvider;

final class AppServiceProvider extends ServiceProvider implements DeferrableProvider
{
    /**
     * Register services.
     */
    public function register(): void
    {
        $this->app->bind(AdminCreateUser::class, AwsAdminCreateUser::class);
    }
}

修正したコード

app/Providers/AppServiceProvider.php
    /**
     * @return string[]
     */
    public function provides(): array
    {
        return [
            AdminCreateUser::class,
        ];
    }

DeferrableProvider と契約して遅延ロードさせた場合は provides() に対象のインターフェースを記述する必要があります。

認識しない場合

それでも認識しない場合はキャッシュクリアとオートローダーの再生成をお試しください。

$ php artisan optimize:clear
$ composer dump-autoload

まとめ

  • サービスプロバイダーが作成されていない
  • config/app.php にサービスプロバイダーが登録されていない
  • DeferrableProvider と契約している場合は provides() にインターフェースを登録
  • キャッシュクリアする
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?