Hi everyone, I am refactoring my API project to Lumen. In 4.2 I had this in routes.php
Route::controller('foo', 'fooController');
This worked out of the box, routing all uri strings to their respected method. In Lumen, the "Route" class is not recognized, even if I add "use App;" at the top. So I changed it like this (it's what NetBeans typehints)
Illuminate\Support\Facades\Route::controller('foo', 'fooController');
Although the class now resolves, it does not work, the error I get is: Class router does not exist
Has this cool Laravel routing feature been removed? Please note I have not used L5, don't know if it works there
Regards
I don't think the Route::controller works with Lumen.
You could just make the rest routes yourself,
In you routes.php file
$app->get('foo', 'fooController@index');
$app->get('foo/{id}', 'fooController@show');
$app->post('foo', 'fooController@store');
$app->put('foo/{id}', 'fooController@update');
$app->delete('foo/{id}', 'fooController@destroy');
// the controllers will need a full class path
It wouldn't take much to make this a small function if you have multiple routes. The you could do something like,
makeControllerRoute('/foo', 'App\Http\Controllers\fooController');
And since you say works "out of the box".. I'm going to add in a reminder about if you want to use the facades you will need to enable them in the app.php file along with the .env load config support.
Dotenv::load(__DIR__.'/../');
$app->withFacades();
$app->withEloquent();
Hope that helps.
http://lumen.laravel.com/docs/controllers, has examples, it is a little different.
$app->get('user/{id}', 'App\Http\Controllers\UserController@showProfile');
I've come to terms that it does not work like in Laravel, so I specified all my routes like you said.
Thanks for you help
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community