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 宇视监控服务器无法登录
  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥15 DruidDataSource一直closing
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥50 power BI 从Mysql服务器导入数据,但连接进去后显示表无数据