Accessing The Current Route
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();
return \Request::route()->getName();
return \Route::currentRouteName();
Example(2)
get current route path
return \Route::getCurrentRoute()->getPath();
Example(3)
get current route action
return \Route::getCurrentRoute()->getActionName(); //response App\Http\Controllers\ProductCRUDController@index
Example(4)
get a list of all routes
$routes = \Route::getRoutes();
foreach ($routes as $route) {
echo $route->getPath().'<br>';
}
Methods used in Route
static void | macro(string $name, object|callable $macro)Register a custom macro. |
static void | mixin(object $mixin, bool $replace = true) Mix another object into the class. |
static bool |
hasMacro(string $name)
Checks if macro is registered. |
static mixed |
__callStatic(string $method, array $parameters)
Dynamically handle calls to the class. |
mixed |
__call(string $method, array $parameters)
Dynamically handle calls to the class. |