Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 804
niko craft Avatar asked Dec 14 '22 15:12

niko craft


1 Answers

Try this solution github

$app->get('/', ['middleware' => 'haspermission:backend-users-list', 'uses' => 'UsersController@all']);
like image 164
Nazar Shchepilov Avatar answered Dec 18 '22 00:12

Nazar Shchepilov