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..
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();
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.
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.
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);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With