douxuqiao6394 2018-03-01 17:39
浏览 82
已采纳

在Git分支交换机Laravel上不存在ReflectionException类

So I read like 100 post about this before deciding on creating this issue.

This problem is actually very specific and it's 100% reproducable.

I created a git branch lets call it storeUpdate, and in this branch I created a file called

app/Http/Controllers/Admin/BatchUpdateStoresController.php

which has the following:

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

and I've added it to the routes.php file:

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

also the relevant part in my composer file:

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

However, when I switch the branch to another git branch, and I try to run php artisan, I get this error:

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

I find the above error interesting, as indeed that file doesn't exist (notice the actual file is app/Http/Controllers/Admin/BatchUpdateStoresController.php, so app != App, but aren't I already taking care of this in the psr-4 section of my composer.json file?

Ideas?

what i tried

all the usual stuff including:

  • composer dump-autoload
  • composer update
  • composer update --no-scripts
  • php artisan cache:clear
  • php artisan api:clear
  • php artisan route:clear

stacktrace

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. udpdate

based on Edwards answer the following worked:

  1. if you go to the git branch that doesn't have that class.. by definition, any php artisan will blow up, so then you already don't have access to some php artisan commands such as php artisan route:clear
  2. therefore, go back to the original branch that has the above class and make sure php artisan runs
  3. run php artisan route:clear
  4. switch branches
  5. profit
  • 写回答

2条回答 默认 最新

  • dongzhuo3202 2018-03-01 23:34
    关注

    Try php artisan route:clear if don't solve, put your complete exception.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 tensorrt 推理 yolov8框出现错误
  • ¥15 用hc 05,做蓝牙控制小车 小车只能说初始遥控方向影响,后续不能更改
  • ¥15 51单片机怎么把每次输入键值保存到数组作为我的确认键的判断条件呢
  • ¥45 easy photo不能使用,求帮助
  • ¥15 c语言字符串单词入门问题报错
  • ¥30 我现在是双非人工智能专业不知道要不要转到软件工程专业
  • ¥15 请问12脉波整流机组的外特性曲线具体是如何推导
  • ¥15 abaqus里的python算法
  • ¥100 如何在思科模拟器中进入CEF模式
  • ¥15 Simulink 仿真如何使用MATLAB function模块获取到仿真过程中某一仿真时刻输入到模块的函数的值?