gpt4 book ai didi

php - ReflectionException 类不存在发生在 git 分支切换 Laravel

转载 作者:太空狗 更新时间:2023-10-29 14:42:40 26 4
gpt4 key购买 nike

所以在决定创建此问题之前,我阅读了 100 篇关于此的帖子。

这个问题实际上非常具体,而且 100% 可重现。

我创建了一个 git 分支,我们称之为 storeUpdate,并在这个分支中创建了一个名为

的文件
app/Http/Controllers/Admin/BatchUpdateStoresController.php

它有以下内容:

namespace App\Http\Controllers\Admin;

use App\Http\Requests;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Repositories\BatchUpdateStores;

class BatchUpdateStoresController extends Controller

我已将它添加到 routes.php 文件中:

app/Http/routes.php|214| $api->put('stores', 'Admin\BatchUpdateStoresController@update');
app/Http/routes.php|215| $api->post('stores', 'Admin\BatchUpdateStoresController@upload');

还有我 Composer 文件中的相关部分:

"autoload": {
"classmap": [
"database"
],
"psr-4": {
"App\\": "app/"
}
},
"autoload-dev": {
"classmap": [
"tests/TestCase.php",
"tests/Helpers/",
"tests/Traits/"
]
},

但是,当我将分支切换到另一个 git 分支,并尝试运行 php artisan 时,出现了这个错误:

[ReflectionException] Class App\Http\Controllers\Admin\BatchUpdateStoresController does not exist

我发现上面的错误很有趣,因为该文件确实不存在(注意实际文件是 app/Http/Controllers/Admin/BatchUpdateStoresController.php,所以 app != App,但我不是已经在我的 composer.json 文件的 psr-4 部分处理了这个问题吗?

想法?

我尝试了什么

所有常见的东西包括:

  • Composer 转储自动加载
  • Composer 更新
  • Composer 更新 --no-scripts
  • php artisan 缓存:清除
  • php artisan api:clear
  • php artisan route:clear

堆栈跟踪

ReflectionException: Class App\Http\Controllers\Admin\BatchUpdateStoresController does not exist in /Users/Shared/dev/php/toters-api/vendor/laravel/framework/src/Illuminate/Container/Container.php:749 
Stack trace: #0 /Users/Shared/dev/php/toters-api/vendor/laravel/framework/src/Illuminate/Container/Container.php(749): ReflectionClass->__construct('App\\Http\\Contro...')
#1 /Users/Shared/dev/php/toters-api/vendor/laravel/framework/src/Illuminate/Container/Container.php(644): Illuminate\Container\Container->build('App\\Http\\Contro...', Array)
#2 /Users/Shared/dev/php/toters-api/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(709): Illuminate\Container\Container->make('App\\Http\\Contro...', Array)
#3 /Users/Shared/dev/php/toters-api/vendor/dingo/api/src/Routing/Route.php(320): Illuminate\Foundation\Application->make('App\\Http\\Contro...')
#4 /Users/Shared/dev/php/toters-api/vendor/dingo/api/src/Routing/Route.php(182): Dingo\Api\Routing\Route->makeControllerInstance()
#5 /Users/Shared/dev/php/toters-api/vendor/dingo/api/src/Routing/Route.php(165): Dingo\Api\Routing\Route->mergeControllerProperties()
#6 /Users/Shared/dev/php/toters-api/vendor/dingo/api/src/Routing/Route.php(144): Dingo\Api\Routing\Route->setupRouteProperties(Object(Illuminate\Http\Request), Object(Illuminate\Routing\Route))
#7 /Users/Shared/dev/php/toters-api/vendor/dingo/api/src/Routing/Router.php(652): Dingo\Api\Routing\Route->__construct(Object(Dingo\Api\Routing\Adapter\Laravel), Object(Illuminate\Foundation\Application), Object(Illuminate\Http\Request), Object(Illuminate\Routing\Route))
#8 /Users/Shared/dev/php/toters-api/vendor/dingo/api/src/Routing/Router.php(714): Dingo\Api\Routing\Router->createRoute(Object(Illuminate\Routing\Route)) #9 /Users/Shared/dev/php/toters-api/vendor/dingo/api/src/Routing/Router.php(744): Dingo\Api\Routing\Router->getRoutes()
#10 /Users/Shared/dev/php/toters-api/bootstrap/cache/routes.php(17): Dingo\Api\Routing\Router->setAdapterRoutes(Array)
#11 /Users/Shared/dev/php/toters-api/vendor/laravel/framework/src/Illuminate/Foundation/Support/Providers/RouteServiceProvider.php(58): require('/Users/Shared/d...')
#12 [internal function]: Illuminate\Foundation\Support\Providers\RouteServiceProvider->Illuminate\Foundation\Support\Providers\{closure}(Object(Illuminate\Foundation\Application))
#13 /Users/Shared/dev/php/toters-api/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(808): call_user_func(Object(Closure), Object(Illuminate\Foundation\Application))
#14 /Users/Shared/dev/php/toters-api/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(757): Illuminate\Foundation\Application->fireAppCallbacks(Array)
#15 /Users/Shared/dev/php/toters-api/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/BootProviders.php(17): Illuminate\Foundation\Application->boot()
#16 /Users/Shared/dev/php/toters-api/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(203): Illuminate\Foundation\Bootstrap\BootProviders->bootstrap(Object(Illuminate\Foundation\Application))
#17 /Users/Shared/dev/php/toters-api/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(267): Illuminate\Foundation\Application->bootstrapWith(Array)
#18 /Users/Shared/dev/php/toters-api/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(113): Illuminate\Foundation\Console\Kernel->bootstrap()
#19 /Users/Shared/dev/php/toters-api/artisan(35): Illuminate\Foundation\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput)) #20

h2。更新

基于 Edwards answer以下工作:

  1. 如果你去到没有那个类的 git 分支.. 根据定义,any php artisan 会爆炸,所以你已经没有了可以访问一些 php artisan 命令,例如 php artisan route:clear
  2. 因此,返回到具有上述类的原始分支并确保 php artisan 运行
  3. 运行 php artisan route:clear
  4. 切换分支
  5. 利润

最佳答案

尝试 php artisan route:clear 如果没有解决,把你的完整异常。

关于php - ReflectionException 类不存在发生在 git 分支切换 Laravel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49055616/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com