Use in your middleware :
$request->route()->getAction();
You'll get all informations you need.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi,
I'm working on a new project builds with Laravel 5. I'm trying to display on each blade templates a variable with the controller name and the action name. Example :
<body class="{{ $body_class }}">
I've created a middleware, i can set my variable but it's impossible to get the current request controller and action. Someone know how to do it ?
Don't use a middleware for this.
If you want to send variables to many views use a View Composer.
Every time you want to share some logic and variables to a set of view, use a view composer. Middleware purpose is to act on the request.
Please or to participate in this conversation.