Is it possible to determine the name of a route group in laravel?
What I'm trying to do is to know that the current request belongs to which group, so I can activate the main menu and submenu for the current route action:
code:
Route::group(['prefix'=>'accounts','as'=>'account.'], function(){ Route::get('/', ' AccountController@index ')->name('index'); Route::get('connect', ' AccountController@connect ')->name('connect'); }); Route::group(['prefix'=>'quotes','as'=>'quote.'], function(){ Route::get('/', ' QuoteController@index ')->name('index'); Route::get('connect', ' QuoteController@create ')->name('create'); });
HTML code for navigation
<ul> <li> // Add class 'active' when any route is open from account route group <a href="{{route('account.index')}}">Accounts</a> <ul> <li> // Add class 'active' when connect sub menu is clicked <a href="{{route('account.connect')}}">Connect Account</a> </li> </ul> </li> <li> // Add class 'active' when any route is open from quote route group <a href="{{route('quote.index')}}">Quotes</a> <ul> <li> // Add class 'active' when create sub menu is clicked <a href="{{route('quote.create')}}">Create Quote</a> </li> </ul> </li> </ul>
Now I want to call a function or something that will give me the current name of the route group.
Examples:
- If I am in the index or create the quotes page
getCurrentRouteGroup() , return quote - If I'm on the indexing or connecting pages page,
getCurrentRouteGroup() should return account
user6067756
source share