get Route name in View
In Blade:
<p style="font-weight:{{ (Route::current()->getName() == 'admin.pages.index' && Request::segment(0) == 'add') ? 'bold' : 'normal' }};">Pages</p>
You may use this (to get current action, i.e. HomeController@index
)
Route::currentRouteAction();
This will return action
like HomeController@index
and you can use something like this in your view
<!-- echo the controller name as 'HomeController' -->{{ dd(substr(Route::currentRouteAction(), 0, (strpos(Route::currentRouteAction(), '@') -1) )) }}<!-- echo the method name as 'index' -->{{ dd(substr(Route::currentRouteAction(), (strpos(Route::currentRouteAction(), '@') + 1) )) }}
The Route::currentRouteName()
method returns the name of your route that is used as 'as' => 'routename'
in your route declaration.
Request::segments()
will return an array with the current url for example:
yoursite/admin/users/create
will give:
array(2) { [0] "admin" [1] "users" [2] "create"}