herrh herrh - 1 year ago 59
PHP Question

How to get grouped routes in blade?

How can I get grouped routes in a blade template?

The grouped routes in php look like:


//player section
Route::group(['prefix' => 'test'], function() {

Route::get('{slug}/{id}', [
'uses' => 'TestController@getTest',
'as' => 'getTest',

Route::get('{slug}/{id}/report', [
'middleware' => 'auth',
'uses' => 'TestController@reportTest',
'as' => 'reportTest',


In a blade template I get single routes by it's
string like

<!-- some html here -->

But how can I get all the routes grouped by prefix
in a blade template?

I want to prevent to write all the routes by it's name like:

(Route::is('getTest', 'reportTest'))

Answer Source

You should be able to do something like this:

@if(Request::route()->getPrefix() === 'test')
<!-- some html here -->

See: https://laravel.com/api/master/Illuminate/Routing/Route.html#method_getPrefix

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download