# \[HELP\] Middleware Parameter is available?

**URL:** <https://discourse.slimframework.com/t/help-middleware-parameter-is-available/4665>\
**Category:** Questions\
**Created:** [February 20, 2021, 2:26pm UTC](https://discourse.slimframework.com/t/help-middleware-parameter-is-available/4665 "2021-02-20T14:26:18Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![raziul](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/raziul/32/1161_2.png) [@raziul](https://discourse.slimframework.com/u/raziul)\
**Post date:** [February 20, 2021, 2:26pm UTC](https://discourse.slimframework.com/t/help-middleware-parameter-is-available/4665/1 "2021-02-20T14:26:18Z")

</div>

I wanted to know if there is any option to use the middleware parameter like laravel.

[Laravel Middleware Docs](https://laravel.com/docs/8.x/middleware#middleware-parameters)

---

<div class="post-metadata">

**Author:** ![tj\_gumis](https://avatars.discourse-cdn.com/v4/letter/t/c89c15/32.png) [@tj\_gumis](https://discourse.slimframework.com/u/tj_gumis)\
**Post date:** [February 20, 2021, 4:24pm UTC](https://discourse.slimframework.com/t/help-middleware-parameter-is-available/4665/2 "2021-02-20T16:24:17Z")

</div>

To make a long story short:  
[Request attributes](https://www.slimframework.com/docs/v4/objects/request.html#attributes).  
So if you’ve done some authentication (AuthenticationMiddleware) and you pass to another one (i.e. AuthorizationMiddleware) you can simply:

_AuthentiacationMiddleware.php_

```php
$request = $request->withAttribute('user', ['whatever']);

```

and then within next middleware in chain:

_AuthentiacationMiddleware.php_

```php
$user = $request->getAttribute('user');

```

---

<div class="post-metadata">

**Author:** ![raziul](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/raziul/32/1161_2.png) [@raziul](https://discourse.slimframework.com/u/raziul)\
**Post date:** [February 20, 2021, 4:43pm UTC](https://discourse.slimframework.com/t/help-middleware-parameter-is-available/4665/3 "2021-02-20T16:43:42Z")

</div>

This is not what I am looking for.  
I know the use of `attribute` but I think that doesn’t satisfies my need.

---

<div class="post-metadata">

**Author:** ![odan](https://avatars.discourse-cdn.com/v4/letter/o/9de053/32.png) [@odan](https://discourse.slimframework.com/u/odan)\
**Post date:** [February 20, 2021, 7:16pm UTC](https://discourse.slimframework.com/t/help-middleware-parameter-is-available/4665/4 "2021-02-20T19:16:49Z")

</div>

Instead of one generic RoleMiddlware you could use add more specific role based middleware to the route groups, e.g.

- `->add(RoleEditorMiddleware::class)`
- `->add(RoleAuthorMiddleware::class)`

The good thing is, they are autoload only on demand, and you could also combine them.

```php
$group->add(RoleAuthorMiddleware::class)
    ->add(RoleEditorMiddleware::class);

```

---

<div class="post-metadata">

**Author:** ![raziul](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/raziul/32/1161_2.png) [@raziul](https://discourse.slimframework.com/u/raziul)\
**Post date:** [February 20, 2021, 7:55pm UTC](https://discourse.slimframework.com/t/help-middleware-parameter-is-available/4665/5 "2021-02-20T19:55:49Z")

</div>

Yeah, I am using it and everything works fine but out of curiosity, just wanted to know if it is possible without making changes to the core framework.

I think this can be done just using the constructor method in the middleware class.
