for some reasons, I couldn't use any of these solutions. so I just declared my route in web.php as $router->get('/api/v1/users', ['as' => 'index', 'uses' => 'UserController@index']) and in my controller I got the name of the route using $routeName = $request->route()[1]['as']; which $request is \Illuminate\Http\Request $request typehinted parameter in index method of UserController
The path method returns the request's URI. So, if the incoming request is targeted at http://example.com/foo/bar, the path method will return foo/bar:
$uri = $request->path();
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:
if ($request->is('admin/*')) {
//
}
To get the full URL, not just the path info, you may use the url method on the request instance:
Using Laravel 5.1, you can use
You can use in template:
Request::path();
is better, and remember toUse Request;
In a Helper file,
Your can use
Route::current()->uri()
to get current URL.Hence, If you compare your route name to set active class on menu then it would be good if you use
Route::currentRouteName()
to get the name of route and comparefor some reasons, I couldn't use any of these solutions. so I just declared my route in
web.php
as$router->get('/api/v1/users', ['as' => 'index', 'uses' => 'UserController@index'])
and in my controller I got the name of the route using$routeName = $request->route()[1]['as'];
which$request
is\Illuminate\Http\Request $request
typehinted parameter inindex
method ofUserController
using Lumen 5.6. Hope it would help someone.
Try this
or
from v5.+
Laravel 5.3
Or if you need the action name
You can find everything about laravel Routes in the Laravel API: http://laravel.com/api/5.0/Illuminate/Routing/Router.html http://laravel.com/api/5.0/Illuminate/Routing.html
Retrieving The Request URI
The path method returns the request's URI. So, if the incoming request is targeted at
http://example.com/foo/bar
, the path method will returnfoo/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: