niko craft
niko craft

Reputation: 2987

how do I put middleware on lumen route

I need to put middleware on route in lumen project. So far I've been working with Laravel but now I'm in a project that is using lumen.

Documentation here: https://lumen.laravel.com/docs/5.4/middleware

gives us

$app->get('admin/profile', ['middleware' => 'auth', function () {
    //
}]);

while my route look like this

$app->get('/', 'UsersController@all');

I've tried this:

$app->get('/', ['middleware' => 'haspermission:backend-users-list'], 'UsersController@all');

but it does not work.

What is the right way to do it if I am not using a function directly in route to return some data?

Upvotes: 5

Views: 9225

Answers (1)

Nazar  Shchepilov
Nazar Shchepilov

Reputation: 146

Try this solution github

$app->get('/', ['middleware' => 'haspermission:backend-users-list', 'uses' => 'UsersController@all']);

Upvotes: 13

Related Questions