GEOFFREY MWANGI GEOFFREY MWANGI - 11 months ago 109
PHP Question

Laravel assigning classes to blade files dynamically fails

I would like to assign classes if a route match a certain pattern.

suppose i have these

urls
as below:

user-management/users
user-management/roles
user-management/role?user=andy
user-management/permissions


Now i would like to add active class to a link. So i have tried:

<li class="{{ (Request::path() == 'user-management/*') ? 'dropdown active ' : 'dropdown' }}">


But the above fails to add active class. Trying with:

<li class="{{ (Request::path() == 'user-management/users') ? 'dropdown active ' : 'dropdown' }}">


Which works when i visit
/user-management/users


How can i make the other one work with all the
user-management
link
urls


What else could be wrong?

Am using laravel 5.5 and my routes in
web.php
are

Route::group(["middleware"=>'auth', 'prefix'=>'user-management'], function (){
Route::get("users", "[email protected]")->name("user-management.users");
Route::get("roles", "[email protected]")->name("user-management.roles");
.....others follow


});

Answer Source

You can do it for all user-management URL. Like:

<li class="{{ Request::is('user-management/*') ? 'dropdown active' : 'dropdown' '' }}>

Hope this works for you!

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