【发布时间】:2021-03-12 13:30:14
【问题描述】:
我有一个带有 laravel 7 的应用程序,我将 composer 1.10 升级到 composer 2.0,我遇到了这个问题:
Illuminate\Contracts\Container\BindingResolutionException
Target class [DatabaseSeeder] does not exist.
at vendor/laravel/framework/src/Illuminate/Container/Container.php:807
803|
804| try {
805| $reflector = new ReflectionClass($concrete);
806| } catch (ReflectionException $e) {
> 807| throw new BindingResolutionException("Target class [$concrete] does not exist.", 0, $e);
808| }
809|
810| // If the type is not instantiable, the developer is attempting to resolve
811| // an abstract type such as an Interface or Abstract Class and there is
+37 vendor frames
38 artisan:37
Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
我尝试了许多解决方案(即使是 Laravel 8 ...),但都没有成功。
这是 composer.json 的自动加载
"psr-4": {
"App\\": "app/",
"DatabaseSeeder\\": "database/seeds"
},
"files": [
"app/helpers.php"
]
}
谢谢!
编辑
这是我刚刚发现的:当我添加 composer.json 时:
"autoload": {
"psr-4": {
"App\\": "app/",
"Database\\Factories\\": "database/factories",
"Database\\Seeds\\": "database/seeds",
"DatabaseSeeder\\": "database/seeds/",
} },
并且我修改了 SeedCommand.php 'src/vendor/laravel/framework/src/Illuminate/Database/Console/Seeds/SeedCommand.php' 的第 84 行,它可以工作!!!
$class = $this->laravel->make($this->input->getOption('class'));
通过
$class = $this->laravel->make('Database\\Seeds\\DatabaseSeeder');
但这绝对是不可维护的...... 那么问题来了,设置DatabaseSeeder的时候就有问题了。
6一个想法?
【问题讨论】:
-
你试过什么来调试这个问题?这甚至与 Composer 有关吗?