Xxmarijnw
Xxmarijnw

Reputation: 304

How to check if on Route with specific parameter in Blade with Laravel 8.x?

I have a sidebar on my website that shows a list of groups. Each group page in this list has the same route, but a different groupname parameter. The route I am using looks like this:

Route::get('/app/group/{groupname}/overview', [OverviewController::class, 'view'])->name("group.overview");

When the user is looking at a specific group, I would like that group to be highlighted in bold in the sidebar. I tried doing the following in my Blade code, but that caused all pages in the sidebar to be highlighted when I visited the page of a specific group:

@if( Route::is( 'group.overview', $membership->group->group_name ) ) class="active" @endif

How do I check whether I am on a specific route, with a specific parameter?

Upvotes: 2

Views: 1756

Answers (2)

DLzer
DLzer

Reputation: 159

You can try something like this: @if(Request::is('overview/'.$membership->group->group_name') ) class="active"

Upvotes: 1

kemp
kemp

Reputation: 703

Try to match by the parameter instead:

@if( request()->route('groupname') == $membership->group->group_name ) class="active" @endif

Upvotes: 4

Related Questions