-
Notifications
You must be signed in to change notification settings - Fork 11.6k
Closed
Description
- Laravel Version: 5.7.8
- PHP Version: 7.2.6
- Database Driver & Version: MariaDB 10.2
Description:
When making HTTP requests to routes within a route group, where an API Resource route group has been registered before, the routes do not match and a 404 response is returned.
Steps To Reproduce:
- Create a new Laravel project
- In your routes file, add the following routes:
$router->group(['prefix' => '/v1', 'middleware' => ['auth:api']], function ($router) {
$router->apiResource('/contacts', 'ContactsController');
$router->group(['prefix' => '/contacts'], function ($router) {
$router->apiResource('/groups', 'Contacts\\GroupsController');
});
});
GET
requests to /api/v1/contacts/groups
then returns 404 responses. However POST
and PUT
requests still work.
The fix for this is changing the order. If I put the contacts api resource below the route group, it then works.
$router->group(['prefix' => '/v1', 'middleware' => ['auth:api']], function ($router) {
$router->group(['prefix' => '/contacts'], function ($router) {
$router->apiResource('/groups', 'Contacts\\GroupsController');
});
$router->apiResource('/contacts', 'ContactsController');
});
Is this intended behaviour? It seems strange that in the first case POST
and PUT
requests work, but GET
requests return 404 responses.
For more information, please see the following Stack Overflow thread - https://stackoverflow.com/questions/52736365/unable-to-make-http-request-to-laravel-endpoint/52736636
Metadata
Metadata
Assignees
Labels
No labels