dingo / dingo/api

Child/Inner route not inheriting parent middlware(s)

Open
#1,752 1 comment 0 reactions 0 assignees View on GitHub
help wanted lumen
Dominant language
PHP
Stars
9.4k
Forks
1.3k
PR merge metrics
No merged PRs in 30d

Description

| Q | A
| ----------------- | ---
| Bug? | yes
| New Feature? | no
| Framework | Lumen
| Framework version | 7.0
| Package version | 3.0.0
| PHP version | 7.2

#### Actual Behaviour

Dingo child/inner route middleware not "inherit" parent's middleware.

#### Expected Behaviour

The child routes should append middlware define from the parent as its own middlware.

#### Steps to Reproduce
```
use Dingo\Api\Routing\Router;

$api->group([
'prefix' => 'foo',
'middleware' => ['auth:api'],
], function (Router $api) {

$api->get('/test', [
'uses' => 'ExampleController@test'
]);

$api->get('/bar', [
'uses' => 'ExampleController@bar',
'middleware' => ['employee'],
]);

$api->get('/biz', [
'uses' => 'ExampleController@biz',
'middleware' => ['employer'],
]);

]);
```
/test has auth:api middlware
foo/bar has employee middlware but it should auth:api and employee
foo/biz has employee middlware but it should auth:api and employer

#### Possible Solutions

Currently what i'm doing is write the full middlware on every child ` 'middleware' => ['auth:api','employer'],` or moving it outside the group.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.