# How can you pass in an (role)argument in a route-group

**URL:** <https://discourse.slimframework.com/t/how-can-you-pass-in-an-role-argument-in-a-route-group/1218>\
**Category:** Questions\
**Created:** [March 1, 2017, 7:57am UTC](https://discourse.slimframework.com/t/how-can-you-pass-in-an-role-argument-in-a-route-group/1218 "2017-03-01T07:57:41Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Keust](https://avatars.discourse-cdn.com/v4/letter/k/77aa72/32.png) [@Keust](https://discourse.slimframework.com/u/Keust)\
**Post date:** [March 1, 2017, 7:57am UTC](https://discourse.slimframework.com/t/how-can-you-pass-in-an-role-argument-in-a-route-group/1218/1 "2017-03-01T07:57:41Z")

</div>

Hi,

For example I have the following route:

```php
$app->group('', function(){

		// Admin functions
 		$this->get('/dashboard/users', 'DashboardController:getUsers')->setName('auth.dashboard.users');

 })->add(new AdminMiddleware($container));

```

Perhaps there will be some other roles ‘e.g. moderator, operator, etc’. I would like to make a more general Middleware like RoleMiddleware.

I saw an example In Laravel (something like):

```php
Route::group(['middleware' => 'role:admin'], function () {
      Route::get('admin', function() {
      // do something
     }
})

```

Is this possible to create in Slim and how would this look?

Then a other question is in bootstrap app I have set-up the following (Globals):

```php
	$view->getEnvironment()->addGlobal('auth', [
				// You will use this method to minimize the SQL queries.
				'check' => $container->auth->check(),
				'user' => $container->auth->user(),
				'admin' => $container->auth->isAdmin(),
		]);

```

With this i now can check in The twig file something like:

```php
{% if auth.admin %}
            <h6>Admin possibilities</h6>            
        {% else %}
            <p>Not an admin</p>
        {% endif %}

```

But how could I check if the user is an admin (_if I did not set the function to be Global_)?

---

<div class="post-metadata">

**Author:** ![robrothedev](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/robrothedev/32/137_2.png) [@robrothedev](https://discourse.slimframework.com/u/robrothedev)\
**Post date:** [March 1, 2017, 2:17pm UTC](https://discourse.slimframework.com/t/how-can-you-pass-in-an-role-argument-in-a-route-group/1218/2 "2017-03-01T14:17:50Z")

</div>

@Keust If I understand your question correctly, you could always add another middleware function to check for user roles:

```
$app->group('', function(){
    	// Admin functions
 		$this->get('/dashboard/users', 'DashboardController:getUsers')->setName('auth.dashboard.users');
 })
 ->add(new UserRoleMiddleware($container))
 ->add(new AdminMiddleware($container));

```

The last middleware added is the first one evaluated.
