Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the current route on middleware in lumen framework?

I have develop the API application using lumen. And for the access permission control. I want to get the current route in middleware. But, I always get null on:

   $route = $request->route();

I already try the way on the Can I get current route information in middleware with Lumen? which using the routeMiddleware and dispatcher. But it's still return null. How could I get the current route on middleware?

Thank a lot..

like image 498
Yo_win Avatar asked Sep 28 '15 08:09

Yo_win


People also ask

How can I know my route in laravel?

You may use the current, currentRouteName, and currentRouteAction methods on the Route facade to access information about the route handling the incoming request: $route = Route::current(); $name = Route::currentRouteName(); $action = Route::currentRouteAction();

What is the use of lumen in laravel?

Lumen utilizes the Illuminate components that power the Laravel framework. As such, Lumen is built to painlessly upgrade directly to Laravel when needed; for example, when you discover that you need more features out of the box than what Lumen offers.

What is laravel and Lumen?

Laravel is a full-stack web application framework that packages or supports a lot of third-party tools and frameworks, whereas Lumen is a micro-framework that is used to develop microservices and API development with the intent of providing speed and high response time.


1 Answers

Please update your Lumen... Everything works with no issues

namespace App\Http\Middleware;

public function handle($request, Closure $next)
{
    $route = $request->route();
    $path = $request->getPathInfo();

    // your code here
    return $next($request);
}
like image 169
Playnox Avatar answered Nov 10 '22 11:11

Playnox