Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

deb44's avatar

Laravel 5.1 - Middleware to route

Hy all!

I have tried to assign middleware to specific route(s). I failed. :(

So...

The doc: http://laravel.com/docs/5.1/middleware#registering-middleware

Laravel version: 5.1.4

Middleware name: AuthMiddleware

app/Http/Kernel.php:

protected $routeMiddleware = [
...
'authm' => \App\Http\Middleware\AuthMiddleware::class,

];

The route (routes.php):

Route::get('/', 'MainController@index', ['middleware' => 'authm']);

If i put the middleware to $middleware (global middlewares), then it works. Only route specific middleware can't.. :(

Please help me! Thank you. :)

0 likes
3 replies
sylar's avatar
Route::get('/', [
    'middleware' => 'authm',
    'uses' => 'MainController@index'
]);

You can always check the registered middlewares with php artisan route:list 10x @Codenator81

deb44's avatar

ohh, i see :) Thank you so much!

Please or to participate in this conversation.