Carlos Salazar
Carlos Salazar

Reputation: 1898

Get the route group name of a route

I'am creating a job on laravel 5.6 that will run only when the route are not inside the route group named administrator so i have many routes like

Route::get('foo','Controller');
Route::get('bar','Controller');
Route::name('administrator')->group(function(){
    Route::get('baz','Controller');
    ....
});

How can I get the group name if I'm inside baz route?

Upvotes: 2

Views: 2363

Answers (1)

The Alpha
The Alpha

Reputation: 146219

You can use something like the following:

Request::route()->getName();

This will return administrator in your case because you've declared the route group as given below:

Route::name('administrator')->group(function(){
    Route::get('baz','Controller');
});

Also, if your route inside a group has it's own name for example:

Route::name('administrator.')->group(function(){
    Route::name('foo')->get('baz', function() {
        dd(Request::route()->getName());
    });
});

You'll get administrator.foo.

Upvotes: 4

Related Questions