使用Laravel 8.75并尝试将composer.json中的php 8.1升级为“php”:“^8.1”并收到错误:Illuminate\Contracts\Container\BindingResolutionException - 目标类[CommandMakeCommand]不存在。
Loading composer repositories with package information
Updating dependencies
Nothing to modify in lock file
Installing dependencies from lock file (including require-dev)
Nothing to install, update or remove
Package swiftmailer/swiftmailer is abandoned, you should avoid using it.
Use symfony/mailer instead.
Generating optimized autoload files
Illuminate\Foundation\ComposerScripts::postAutoloadDump
@php artisan package:discover --ansi
Illuminate\Contracts\Container\BindingResolutionException
Target class [CommandMakeCommand] does not exist.
at
供应商/laravel/framework/src/Illuminate/Container/Container.php:879
875▕
876▕ try {
877▕ $reflector = new ReflectionClass($concrete);
878▕ } catch (ReflectionException $e) {
879▕ throw new BindingResolutionException("Target class [$concrete] does not exist.", 0, $e);
880▕ }
881▕
882▕ // If the type is not instantiable, the developer is attempting to resolve
883▕ // an abstract type such as an Interface or Abstract Class and there is
+13 vendor frames
14 artisan:37
Illuminate\Foundation\Console\Kernel::handle()
Script @php artisan package:discover --ansi handling the post-autoload-
dump event returned with error code 1
我也有同样的问题,在我的例子中,nwidart/laravel-modules包升级到8.3版本,我降级到8.2版本,问题解决了
参见这里:https://docs.laravelmodules.com/v9/introduction
如果您有现有的配置文件,并且收到错误消息:
Target class [CommandMakeCommand] does not exist
然后配置文件需要更新,首先导入命令类:
use Nwidart\Modules\Commands;
接下来将命令数组替换为:
'commands' => [
Commands\CommandMakeCommand::class,
Commands\ComponentClassMakeCommand::class,
Commands\ComponentViewMakeCommand::class,
Commands\ControllerMakeCommand::class,
Commands\DisableCommand::class,
Commands\DumpCommand::class,
Commands\EnableCommand::class,
Commands\EventMakeCommand::class,
Commands\JobMakeCommand::class,
Commands\ListenerMakeCommand::class,
Commands\MailMakeCommand::class,
Commands\MiddlewareMakeCommand::class,
Commands\NotificationMakeCommand::class,
Commands\ProviderMakeCommand::class,
Commands\RouteProviderMakeCommand::class,
Commands\InstallCommand::class,
Commands\ListCommand::class,
Commands\ModuleDeleteCommand::class,
Commands\ModuleMakeCommand::class,
Commands\FactoryMakeCommand::class,
Commands\PolicyMakeCommand::class,
Commands\RequestMakeCommand::class,
Commands\RuleMakeCommand::class,
Commands\MigrateCommand::class,
Commands\MigrateRefreshCommand::class,
Commands\MigrateResetCommand::class,
Commands\MigrateRollbackCommand::class,
Commands\MigrateStatusCommand::class,
Commands\MigrationMakeCommand::class,
Commands\ModelMakeCommand::class,
Commands\PublishCommand::class,
Commands\PublishConfigurationCommand::class,
Commands\PublishMigrationCommand::class,
Commands\PublishTranslationCommand::class,
Commands\SeedCommand::class,
Commands\SeedMakeCommand::class,
Commands\SetupCommand::class,
Commands\UnUseCommand::class,
Commands\UpdateCommand::class,
Commands\UseCommand::class,
Commands\ResourceMakeCommand::class,
Commands\TestMakeCommand::class,
Commands\LaravelModulesV6Migrator::class,
],
只需添加这一行:
use Nwidart\Modules\Commands\CommandMakeCommand;
在第一个
config/modules.php
文件中作为 namespace
上面的命名空间只会解决commandMakeCommand的问题,但如果你想设置所有命令命名空间,那么你需要在顶部添加命名空间。
namespace Nwidart\Modules\Commands;
希望这有帮助(首先备份您的项目):
首先通过运行删除nwidart/laravel-modules:
composer remove nwidart/laravel-modules
然后通过删除来删除
config/modules.php
。
通过运行重新安装 nwidart/laravel-modules:
composer require nwidart/laravel-modules
如果有人仍在寻找答案,请按照以下步骤操作
如本链接所述,请参阅此处:https://docs.laravelmodules.com/v9/introduction
如果您有现有的配置文件,并且收到错误消息:
Target class [CommandMakeCommand] does not exist
然后配置文件需要更新,首先导入命令类,然后在配置文件夹中更新
modules.php
文件包括
use Nwidart\Modules\Commands;
然后将命令数组替换为:在每个值之前添加
Commands\
或简单复制并替换数组
'commands' => [
Commands\CommandMakeCommand::class,
Commands\ComponentClassMakeCommand::class,
Commands\ComponentViewMakeCommand::class,
Commands\ControllerMakeCommand::class,
Commands\DisableCommand::class,
Commands\DumpCommand::class,
Commands\EnableCommand::class,
Commands\EventMakeCommand::class,
Commands\JobMakeCommand::class,
Commands\ListenerMakeCommand::class,
Commands\MailMakeCommand::class,
Commands\MiddlewareMakeCommand::class,
Commands\NotificationMakeCommand::class,
Commands\ProviderMakeCommand::class,
Commands\RouteProviderMakeCommand::class,
Commands\InstallCommand::class,
Commands\ListCommand::class,
Commands\ModuleDeleteCommand::class,
Commands\ModuleMakeCommand::class,
Commands\FactoryMakeCommand::class,
Commands\PolicyMakeCommand::class,
Commands\RequestMakeCommand::class,
Commands\RuleMakeCommand::class,
Commands\MigrateCommand::class,
Commands\MigrateRefreshCommand::class,
Commands\MigrateResetCommand::class,
Commands\MigrateRollbackCommand::class,
Commands\MigrateStatusCommand::class,
Commands\MigrationMakeCommand::class,
Commands\ModelMakeCommand::class,
Commands\PublishCommand::class,
Commands\PublishConfigurationCommand::class,
Commands\PublishMigrationCommand::class,
Commands\PublishTranslationCommand::class,
Commands\SeedCommand::class,
Commands\SeedMakeCommand::class,
Commands\SetupCommand::class,
Commands\UnUseCommand::class,
Commands\UpdateCommand::class,
Commands\UseCommand::class,
Commands\ResourceMakeCommand::class,
Commands\TestMakeCommand::class,
Commands\LaravelModulesV6Migrator::class,
],
您可以尝试降级composer.json文件中的nwidart/laravel-modules版本。只需将此行更改为以下行即可。
"nwidart/laravel-modules": "8.2.*"
然后删除composer.lock文件,现在运行此命令。
composer install
在
config/modules
添加名称完整路径到命令 Nwidart\Modules\Commands
'commands' => [
Nwidart\Modules\Commands\CommandMakeCommand::class
...
],
这不是相关路线或应用程序的任何其他部分, 当您无法运行 Composer Update 或 Artisan 命令时 您在启动 Laravel 时遇到问题,在这种情况下: 转到您的配置文件夹打开模块文件并检查“Command”键 我的问题就这样解决了! 美好的一天!
使用目标类的完整路径
例如:
use App\Models\Company;
或
Route::resource('companies', App\Http\Controllers\CompanyController::class);