含有php artisan的所有命令运行都报错

1. 运行环境

1). 当前使用的 Laravel 版本?

Laravel Framework 8.61.0

2). 当前使用的 php/php-fpm 版本?

PHP 版本:PHP 7.3.31

php-fpm 版本:7.3

3). 当前系统

CentOS 7

4). 业务环境

生产环境

5). 相关软件版本

nginx version: nginx/1.20.1
mysql Ver 5.7.37

2. 问题描述?

我在使用了 php artisan route:cache 后,我又键入了php artisan config:cache,此时出现报错,并且我尝试输入其他带有php artisan的命令都出现相关报错

错误信息显示未找到App\Http\Controllers\V1\AttachmentController,我在我的api.php中发现了相关代码:
$api->get(‘attachment/download/{md5}’, [‘as’ => ‘attachment.download’,’uses’ => ‘AttachmentController@download’, ]);
我把含有该controller的所有代码段都注释,但是运行php artisan 还是报相同的错误。

已经尝试重启服务器、使用composer install和composer update命令,都没有作用。

3. 您期望得到的结果?

Laravel

4. 您实际得到的结果?

以下报错内容为运行php artisan命令后的报错信息:
online.ERROR: Target class [App\Http\Controllers\V1\AttachmentController] does not exist. {“exception”:”[object] (Illuminate\Contracts\Container\BindingResolutionException(code: 0): Target class [App\Http\Controllers\V1\AttachmentController] does not exist. at /usr/share/nginx/html/kangyang/vendor/laravel/framework/src/Illuminate/Container/Container.php:879)
[stacktrace]

#0 /usr/share/nginx/html/kangyang/vendor/laravel/framework/src/Illuminate/Container/Container.php(758): Illuminate\Container\Container->build(‘App\\Http\\Contro…’)

#1 /usr/share/nginx/html/kangyang/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(851): Illuminate\Container\Container->resolve(‘App\\Http\\Contro…’, Array, true)

#2 /usr/share/nginx/html/kangyang/vendor/laravel/framework/src/Illuminate/Container/Container.php(694): Illuminate\Foundation\Application->resolve(‘App\\Http\\Contro…’, Array)

#3 /usr/share/nginx/html/kangyang/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(836): Illuminate\Container\Container->make(‘App\\Http\\Contro…’, Array)

#4 /usr/share/nginx/html/kangyang/vendor/dingo/api/src/Routing/Route.php(284): Illuminate\Foundation\Application->make(‘App\\Http\\Contro…’)

#5 /usr/share/nginx/html/kangyang/vendor/dingo/api/src/Routing/Route.php(144): Dingo\Api\Routing\Route->makeControllerInstance()

#6 /usr/share/nginx/html/kangyang/vendor/dingo/api/src/Routing/Route.php(126): Dingo\Api\Routing\Route->mergeControllerProperties()

#7 /usr/share/nginx/html/kangyang/vendor/dingo/api/src/Routing/Route.php(98): Dingo\Api\Routing\Route->setupRouteProperties(Object(Illuminate\Http\Request), Object(Illuminate\Routing\Route))

#8 /usr/share/nginx/html/kangyang/vendor/dingo/api/src/Routing/Router.php(653): Dingo\Api\Routing\Route->__construct(Object(Dingo\Api\Routing\Adapter\Laravel), Object(Illuminate\Foundation\Application), Object(Illuminate\Http\Request), Object(Illuminate\Routing\Route))

#9 /usr/share/nginx/html/kangyang/vendor/dingo/api/src/Routing/Router.php(715): Dingo\Api\Routing\Router->createRoute(Object(Illuminate\Routing\Route))

#10 /usr/share/nginx/html/kangyang/vendor/dingo/api/src/Routing/Router.php(745): Dingo\Api\Routing\Router->getRoutes()

#11 /usr/share/nginx/html/kangyang/bootstrap/cache/routes-v7.php(9495): Dingo\Api\Routing\Router->setAdapterRoutes(Array)

#12 /usr/share/nginx/html/kangyang/vendor/laravel/framework/src/Illuminate/Foundation/Support/Providers/RouteServiceProvider.php(108): require(‘/usr/share/ngin…’)

#13 /usr/share/nginx/html/kangyang/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(967): Illuminate\Foundation\Support\Providers\RouteServiceProvider->Illuminate\Foundation\Support\Providers\{closure}(Object(Illuminate\Foundation\Application))

#14 /usr/share/nginx/html/kangyang/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(910): Illuminate\Foundation\Application->fireAppCallbacks(Array)

#15 /usr/share/nginx/html/kangyang/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/BootProviders.php(17): Illuminate\Foundation\Application->boot()

#16 /usr/share/nginx/html/kangyang/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(237): Illuminate\Foundation\Bootstrap\BootProviders->bootstrap(Object(Illuminate\Foundation\Application))

#17 /usr/share/nginx/html/kangyang/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(310): Illuminate\Foundation\Application->bootstrapWith(Array)

#18 /usr/share/nginx/html/kangyang/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(127): Illuminate\Foundation\Console\Kernel->bootstrap()

#19 /usr/share/nginx/html/kangyang/artisan(37): Illuminate\Foundation\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))

#20 {main}

《L05 电商实战》
从零开发一个电商项目,功能包括电商后台、商品 & SKU 管理、购物车、订单管理、支付宝支付、微信支付、订单退款流程、优惠券等
《G01 Go 实战入门》
从零开始带你一步步开发一个 Go 博客项目,让你在最短的时间内学会使用 Go 进行编码。项目结构很大程度上参考了 Laravel。
gongmeng
最佳答案

App\Http\Controllers\V1\AttachmentController
1、看一下这个控制器存不存在,以及对应的命名空间是否设置正确
2、看一下是否还有相关的路由未注释

1年前 评论
iced (楼主) 1年前
iced (楼主) 1年前
gongmeng (作者) 1年前
讨论数量: 7
gongmeng

App\Http\Controllers\V1\AttachmentController
1、看一下这个控制器存不存在,以及对应的命名空间是否设置正确
2、看一下是否还有相关的路由未注释

1年前 评论
iced (楼主) 1年前
iced (楼主) 1年前
gongmeng (作者) 1年前
ShiKi

vendor 文件删了,重装试试

1年前 评论

composer dump-autoload 试试

1年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!