Reputation: 3118
I already had a look at other post about how to fix the ReflectionException issue in laravel Lumen, using this:
$request = Illuminate\Http\Request::capture();
$app->run($request);
However it is not solving my problem. I have a controller called AccountController.php and placed in app/Http/Controllers/Account folder and here is the code:
<?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);
}
}
And this is my route file placed in /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');
});
When I test with Postman the get request which returns a simple 'Hello World' is working fine, but the POST call to api/v1/account/createNewAccount will always fail whatever I do:
ReflectionException in Container.php line 681: Class App\Http\Controllers\App\Http\Controllers\Account\AccountController does not exist in Container.php line 681 at ReflectionClass->__construct('App\Http\Controllers\App\Http\Controllers\Account\AccountController') in Container.php line 681 at Container->build('App\Http\Controllers\App\Http\Controllers\Account\AccountController') in Container.php line 565 at Container->make('App\Http\Controllers\App\Http\Controllers\Account\AccountController') in Application.php line 208 at Application->make('App\Http\Controllers\App\Http\Controllers\Account\AccountController') in RoutesRequests.php line 677 at Application->callControllerAction(array(true, array('uses' => 'App\Http\Controllers\App\Http\Controllers\Account\AccountController@createNewAccount'), array())) in RoutesRequests.php line 644 at Application->callActionOnArrayBasedRoute(array(true, array('uses' => 'App\Http\Controllers\App\Http\Controllers\Account\AccountController@createNewAccount'), array())) in RoutesRequests.php line 629 at Application->handleFoundRoute(array(true, array('uses' => 'App\Http\Controllers\App\Http\Controllers\Account\AccountController@createNewAccount'), array())) in RoutesRequests.php line 528 at Application->Laravel\Lumen\Concerns{closure}() in RoutesRequests.php line 782 at Application->sendThroughPipeline(array(), object(Closure)) in RoutesRequests.php line 534 at Application->dispatch(object(Request)) in RoutesRequests.php line 475 at Application->run(object(Request)) in index.php line 29
I am using "laravel/lumen-framework": "5.4.*".
Upvotes: 1
Views: 870
Reputation: 3118
There is no reply to this particular issue, I decided to build my API with Dingo API: https://github.com/dingo/api It is a good package to build API with Laravel/lumen. They created their own routing system and things are going much better since.
Upvotes: 1