Lumen route:
+--------+---------------------------+------------+----------------------------------------------------+---------+--------------------------+
| Verb | Path | NamedRoute | Controller | Action | Middleware |
+--------+---------------------------+------------+----------------------------------------------------+---------+--------------------------+
| GET | / | | None | Closure | |
| POST | /login | | AppHttpControllersAuthAuthController | login | |
| GET | /setting/menu | | AppHttpControllersSettingMenuController | index | auth, auth.authorization |
| POST | /setting/menu | | AppHttpControllersSettingMenuController | store | auth, auth.authorization |
| GET | /setting/menu/{id} | | AppHttpControllersSettingMenuController | show | auth, auth.authorization |
| PUT | /setting/menu/{id} | | AppHttpControllersSettingMenuController | update | auth, auth.authorization |
| DELETE | /setting/menu/{id} | | AppHttpControllersSettingMenuController | destroy | auth, auth.authorization |
+--------+---------------------------+------------+----------------------------------------------------+---------+--------------------------+
$request->route()
only return route name, How can I get the route path like /setting/menu/{id}
?
I used Lumen 9.x
3
Answers
You should use
you better name your route to make it easier for you, https://lumen.laravel.com/docs/9.x/routing#named-routes.
like this
and then you can call
It may be desirable to obtain the parameterised path pattern for logging purposes on shutdown.
Here is a solution for Lumen/Laravel that will work in any situation, especially where the routes are not named (where
$request->route()[1]['as']
cannot be used)And use it like this
Could also set it up as a "service provider"
If it’s possible to do so, naming all of your paths with "as" will enable a faster solution