Is there any way to define the name of route group in laravel?
What I'm trying to accomplish by this is to know that the current request belongs to which group so I can make active the main menu and sub menu by 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');
});
Navigation HTML Code
<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 what I want is to call a function or something which will give me the current route's group name.
Examples:
- If I'm on index or create page of quotes
getCurrentRouteGroup()
should returnquote
- If I'm on index or connect page of accounts
getCurrentRouteGroup()
should returnaccount