Problem
Before I used to take the following code in order to retrieve the current route name. Wondering if that changed in Laravel 5 or 6 ?
How can I do it in Laravel v5 and Laravel v6?
Solution
You can probably start with this
or if that doesn’t work, here is another option
Laravel v5.2
Or if you need the action name
Laravel 5.2 route documentation
Retrieving The Request URI
The path method returns the request’s URI. So, if the incoming request is targeted at https://laravel-recipes.com/foo/bar, the path method will return foo/bar:
The is method allows you to verify that the incoming request URI matches a given pattern. You may use the * character as a wildcard when utilizing this method:
//
}
To get the full URL, not just the path info, you may use the url method on the request instance:
Laravel v5.3 … v5.8
$name = Route::currentRouteName();
$action = Route::currentRouteAction();
Laravel 5.3 route documentation
Laravel v6.x
$name = Route::currentRouteName();
$action = Route::currentRouteAction();
** Current as of Nov 11th 2019 – version 6.5 **
Laravel 6.x route documentation
There is an option to use request to get route