Get the currently dispatched route instance.
public static getCurrentRoute ( ) : Illuminate\Routing\Route | ||
return | Illuminate\Routing\Route |
use Illuminate\Support\Facades\Route; $currentRouteName = Route::currentRouteName(); $currentUrl = Route::current()->uri(); $currentAction = Route::current()->getActionName();
use Symfony\Component\Routing\RouterInterface; public function indexAction(RouterInterface $router) { $currentRoute = $router->match($request->getPathInfo()); $currentRouteName = $currentRoute['_route']; }In this example, we inject a `RouterInterface` instance into a controller action method. We then use the `match` method to retrieve information about the current route based on the request's path information. We then retrieve the name of the current route from the resulting array of route parameters. Both of these examples use package/libraries specifically designed for routing in PHP applications. In Laravel, the `Route` facade belongs to the Laravel Framework, while in Symfony, the `RouterInterface` belongs to the Symfony Routing component.
public static getCurrentRoute ( ) : Illuminate\Routing\Route | ||
return | Illuminate\Routing\Route |