Hi, how can I enable routing to work in my Lumen?
I added this in the routes files without success:
$api = app('Dingo\Api\Routing\Router');
$api->version('v1', function ($api) {
$api->get('users/{id}', 'App\Api\Controllers\UserController@show');
});
Same problem here using the example route in Laravel 5.4...
I'm on Lumen 5.4.. Probably a 5.4 thing?
Just have updated my project to lumen 5.4 too and same problem... all my routes are downed.
Only the '/' route is responding, anything else is ignored, might it be $app->get or
$api = app('DingoApiRoutingRouter');
$api->version('v1', function ($api) {
$api->get('users/{id}', 'AppApiControllersUserController@show');
});
like @renege
I've had the same problem. Here's the code I used. It feels a bit messy but it works:
app/Providers/RouteServiceProvider.php
/**
* Define the routes for the application.
*
* @return void
*/
public function map()
{
$api = app('Dingo\Api\Routing\Router');
$api->version('v1', function ($api) {
require base_path('routes/v1.php');
});
}
routes/v1.php
$api->get('/', ['as' => 'home', 'uses' => 'App\Api\V1\HomeController@index']);
$api->get('test', ['as' => 'test', 'uses' => 'App\Api\V1\HomeController@test']);
// etc
Is there an "official" way of doing this?
I've finally managed to make it works with this code :
In public/index.php, I've changed how the app start to run.
// basic usage was :
$app->run();
// I had changed it for this version while using nginx & local wamp for Lumen 5.2
$app->run($app->make('request'));
// But everything was finally fixed when I changed to this new version :
$request = Illuminate\Http\Request::capture();
$app->run($request);
And I've also changed how the routes were stored.
// legacy folder (lumen 5.2)
My route.php was in : app/Http/routes.php
Now I've changed it for the new location (lumen 5.3+) and split into several files :
/routes/web.php
/routes/api/v1.php
/routes/api/v2.php
Then in bootstrap/app.php
$app->group(['namespace' => 'App\Http\Controllers'], function ($app) {
// previous declaration Lumen 5.2
//require __DIR__.'/../app/Http/routes.php';
// new declaration for Lumen 5.4
require __DIR__.'/../routes/api/v1.php';
require __DIR__.'/../routes/api/v2.php';
require __DIR__.'/../routes/web.php';
});
routes/api/v1.php
$api = app('Dingo\Api\Routing\Router');
// v1 version API
// choose version add this in header Accept:application/vnd.lumen.v1+json
$api->version('v1', ['namespace' => 'App\Http\Controllers\Api\V1'], function ($api) {
// all my v1 routes here as usual...
});
routes/api/v2.php
$api = app('Dingo\Api\Routing\Router');
// v2 version API
// choose version add this in header Accept:application/vnd.lumen.v2+json
$api->version('v2', ['namespace' => 'App\Http\Controllers\Api\V2'], function ($api) {
// all my v2 routes here as usual...
});
routes/web.php for classic lumen routes + oauth2
$app->get('/', function () use ($app) {
return $app->version();
});
$app->post('oauth2/token', ...);
Then everything went back to normal... all dingo api REST routes, my oauth2 routes with Passport 2.0...
@meistocko Are you using laravel 5.4 and latest dingo? your solution doesn't work for me.
@xcaptain according to my composer.lock I'm using Dingo dev-master and Laravel v5.4.12
Google brought me here, so I wanted to share my experience.
I exactly had the same issue with Lumen after upgrading 5.4.
For a reason I can't exactly remember, my public/index.php had this line to run the application:
$app->run($app->make('request'));
And like this, Lumen <=5.3 was working, but with 5.4.x every route was returning to index.
So, I simply reverted it to default one:
$app->run();
and my issue is resolved.
I don't know if it's related, but I hope it'll be useful for you or other Googlers. Took me 2 hours to figure it out (index.php was the last file I checked).
Most helpful comment
Google brought me here, so I wanted to share my experience.
I exactly had the same issue with Lumen after upgrading 5.4.
For a reason I can't exactly remember, my
public/index.phphad this line to run the application:And like this, Lumen <=5.3 was working, but with 5.4.x every route was returning to index.
So, I simply reverted it to default one:
and my issue is resolved.
I don't know if it's related, but I hope it'll be useful for you or other Googlers. Took me 2 hours to figure it out (index.php was the last file I checked).