我已经看过其他关于如何解决laravel Lumen中的 ReflectionException 问题的帖子,使用它:
$request = Illuminate\Http\Request::capture();
$app->run($request);
但它并没有解决我的问题 . 我有一个名为AccountController.php的控制器,放在app / Http / Controllers / Account文件夹中,这里是代码:
<?php
namespace App\Http\Controllers\Account;
use App\Account;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class AccountController extends Controller {
public function createNewAccount(Request $request) {
$newAccount = Account::create($request->all());
return response()->json($newAccount);
}
}
这是我的路径文件放在/routes/web.php中:
<?php
$app->get('/hello', function () use ($app) {
return 'Hello World!';
});
$app->group(['prefix' => 'api/v1','namespace' => 'App\Http\Controllers\Account'], function($app)
{
$app->post('account','AccountController@createNewAccount');
});
当我使用Postman测试时返回一个简单的'Hello World'的get请求工作正常,但是对 api/v1/account/createNewAccount 的POST调用将始终失败,无论我做什么:
Container.php第681行中的ReflectionException:Class App \ Http \ Controllers \ App \ Http \ Controllers \ Account \ AccountController在ReflectionClass中的Container.php第681行中不存在 - > __ construct('App \ Http \ Controllers \ App \ Http位于Container-> make的Container.php第565行的Container-> build('App \ Http \ Controllers \ App \ Http \ Controllers \ Account \ AccountController')中的Container.php第681行中的\ Controllers \ Account \ AccountController')在Application_php第208行中的'App \ Http \ Controllers \ App \ Http \ Controllers \ Account \ AccountController')在RoutesRequests中的Application-> make('App \ Http \ Controllers \ App \ Http \ Controllers \ Account \ AccountController') .php第677行在Application-> callControllerAction(数组(true,数组('使用'=>'App \ Http \ Controllers \ App \ Http \ Controllers \ Account \ AccountController @ createNewAccount'),array()))中的RoutesRequests . 应用程序中的php行644-> callActionOnArrayBasedRoute(数组(true,数组)('uses'=>'App \ Http \ Controllers \ App \ Http \ Controllers \ Account \ AccountController @ createNewAcco在应用程序 - > handleFoundRoute的RoutesRequests.php第629行中的(),array()))数组(true,数组('使用'=>'App \ Http \ Controllers \ App \ Http \ Controllers \ Account \ AccountController @ createNewAccount '),array()))在RoutesRequests.php第528行的Application-> Laravel \ Lumen \ Concerns ()在RoutesRequests.php第782行的Application-> sendThroughPipeline(array(),object(Closure))中RoutesRequests.php第534行在Application-> dispatch(object(Request))中的RoutesRequests.php第475行,在Application-> run(object(Request))中的index.php第29行
我正在使用“laravel / lumen-framework”:“5.4 . *” .
1 回答
没有回复这个特定的问题,我决定使用Dingo API构建我的API:https://github.com/dingo/api这是一个用Laravel / lumen构建API的好方法 . 他们创建了自己的路由系统,事情进展得更好 .