How to define route group name in laravel
This should work:
Route::group(['prefix'=>'accounts','as'=>'account.'], function(){
Route::get('/', ['as' => 'index', 'uses' => 'AccountController@index']);
Route::get('connect', ['as' => 'connect', 'uses' = > 'AccountController@connect']);
});
Look here for an explanation and in the official documentation (under Route Groups & Named Routes).
Update
{{ $routeName = \Request::route()->getName() }}
@if(strpos($routeName, 'account.') === 0)
// do something
@endif
Alternative from Rohit Khatri
function getCurrentRouteGroup() {
$routeName = Illuminate\Support\Facades\Route::current()->getName();
return explode('.',$routeName)[0];
}
You can use Route::name()->group(...)
to prefix all names for a group of routes
Route::name('foo.')->prefix('xyz')->group(function() {
Route::get('path', 'SomeController@method')->name('bar');
});
Here route('foo.bar')
resolves to url /xyz/path
See related Laravel Docs
Don't forget to append dot in the prefix name :-)