我手动删除了一个 Trait 文件,现在我得到 "Trait 'App\Http\Controllers\CommonTrait' not found"。我该如何解决?

I manually delated a Trait file, now I get "Trait 'App\Http\Controllers\CommonTrait' not found". How do I fix this?

手动删除编译器不再需要的 Trait 文件后,我看到编译器正在查找 Controller 文件夹而不是 Traits 文件夹。 我试过 composer dump-autoloadphp artisan clear-compiledphp artisan /clear-cachephp artisan optimize。我该如何解决这个问题?

After manually deleting a Trait file that was no longer needed by the compiler I see that the compiler is looking in the Controller folder instead of the Traits folder.

我猜这意味着你将 Trait 文件 移动到了另一个目录?

因为 composer 通常是 configured to use the PSR-4 autoloading 这将需要您还更改移动特征的命名空间。

即试图加载 App\Http\Controllers\CommonTrait 自动加载器正在 src/Http/Controllers/CommonTrait.php 文件中寻找特征。如果您将该文件移动到 src/Http/Controllers/Traits/CommonTrait.php,则必须将 Trait 的命名空间更改为

namespace App\Http\Controllers\Traits;

并将其导入以用作

use App\Http\Controllers\Traits\CommonTrait;

我的问题的答案是确保您的代码中没有任何内容使用特征。我找到了一个仍在使用该特征的控制器。大新手错误。也许是时候让这只老海狗...