Laravel 无法声明 class Symfony\Component\HttpFoundation\AcceptHeader,因为该名称已被使用

Laravel Cannot declare class Symfony\Component\HttpFoundation\AcceptHeader, because the name is already in use

我刚刚完成了几个月前在 Laravel 中完成的一个项目。该项目还利用 Laravel Voyager - 管理面板包。

浏览到 http://example.com/admin 后,我收到了这个莫名其妙的错误,我也不确定如何调试它。它看起来像这样:

Fatal error: Cannot declare class Symfony\Component\HttpFoundation\AcceptHeader, because the name is already in use in /c/Users/User/Code/example-website/vendor/symfony/http-foundation/AcceptHeader.php on line 22

Fatal error: Uncaught Error: Class 'Symfony\Component\HttpFoundation\AcceptHeaderItem' not found in /c/Users/User/Code/example-website/vendor/symfony/http-foundation/AcceptHeader.php:61 Stack trace: #0 [internal function]: Symfony\Component\HttpFoundation\AcceptHeader::Symfony\Component\HttpFoundation\{closure}(Array) #1 /c/Users/User/Code/example-website/vendor/symfony/http-foundation/AcceptHeader.php(57): array_map(Object(Closure), Array) #2 /c/Users/User/Code/example-website/vendor/symfony/http-foundation/Request.php(1664): Symfony\Component\HttpFoundation\AcceptHeader::fromString('text/html,appli...') #3 /c/Users/User/Code/example-website/vendor/laravel/framework/src/Illuminate/Http/Concerns/InteractsWithContentTypes.php(54): Symfony\Component\HttpFoundation\Request->getAcceptableContentTypes() #4 /c/Users/User/Code/example-website/vendor/laravel/framework/src/Illuminate/Http/Concerns/InteractsWithContentTypes.php(44): Illuminate\Http\Request->wantsJson() #5 /c/Users/User/Code/example-website/vendor/laravel/framework/src/Illumina in /c/Users/User/Code/example-website/vendor/symfony/http-foundation/AcceptHeader.php on line 61

这个错误是意料之中的,我以前从未在我的项目中(或其他任何地方)见过它。

我该如何调试这个问题?

作为完整性检查,删除 vendor 目录,然后删除 运行 composer install 以重新获取您的依赖项并查看错误是否已解决。如果没有,则尝试 composer update 获取可能已解决此问题的最新版本的依赖项。