I use the Lumen framework for first time, the route /
to my HomeController is not working.
This is my route.php:
$app->get('/', 'HomeController@index');
But I get the following error:
[2015-04-17 07:03:41] lumen.ERROR: exception 'ReflectionException' with message 'Class HomeController does not exist' in /Users/refear99/Web/qingsongchou_api/vendor/illuminate/container/Container.php:776
Stack trace:
#0 /Users/refear99/Web/qingsongchou_api/vendor/illuminate/container/Container.php(776): ReflectionClass->__construct('HomeController')
#1 /Users/refear99/Web/qingsongchou_api/vendor/illuminate/container/Container.php(656): Illuminate\Container\Container->build('HomeController', Array)
#2 /Users/refear99/Web/qingsongchou_api/vendor/laravel/lumen-framework/src/Application.php(358): Illuminate\Container\Container->make('HomeController', Array)
#3 /Users/refear99/Web/qingsongchou_api/vendor/laravel/lumen-framework/src/Application.php(1184): Laravel\Lumen\Application->make('HomeController')
#4 /Users/refear99/Web/qingsongchou_api/vendor/laravel/lumen-framework/src/Application.php(1157): Laravel\Lumen\Application->callControllerAction(Array)
#5 /Users/refear99/Web/qingsongchou_api/vendor/laravel/lumen-framework/src/Application.php(1142): Laravel\Lumen\Application->callActionOnArrayBasedRoute(Array)
#6 /Users/refear99/Web/qingsongchou_api/vendor/laravel/lumen-framework/src/Application.php(1120): Laravel\Lumen\Application->handleArrayBasedFoundRoute(Array)
#7 /Users/refear99/Web/qingsongchou_api/vendor/laravel/lumen-framework/src/Application.php(1058): Laravel\Lumen\Application->handleFoundRoute(Array)
#8 /Users/refear99/Web/qingsongchou_api/vendor/laravel/lumen-framework/src/Application.php(1006): Laravel\Lumen\Application->dispatch(NULL)
#9 /Users/refear99/Web/qingsongchou_api/public/index.php(28): Laravel\Lumen\Application->run()
#10 {main}
This is my HomeController.php in /app/Http/Controllers/
<?php namespace App\Http\Controllers;
class HomeController extends Controller {
public function index()
{
echo 123;
}
}
What could the problem be?
You have to use the fully qualified classname:
$app->get('/', 'App\Http\Controllers\HomeController@index');
OR wrap all routes in a group (which is actually how it's done under the hood in Laravel 5)
$app->group(['namespace' => 'App\Http\Controllers'], function($group){
$group->get('/', 'HomeController@index');
$group->get('foo', 'FooController@index');
});