DEV Community

Cover image for Styling active route menu item in laravel
James Bhatta
James Bhatta

Posted on

Styling active route menu item in laravel

You can check if the current route is active just with

request()->routeIs('admin.cities')
Enter fullscreen mode Exit fullscreen mode

Or even sub-routes (like editing, creating, or whatever with

request()->routeIs('admin.cities*')
Enter fullscreen mode Exit fullscreen mode

If you prefer to use the route facade, you still can do that with

Route::named('admin.cities*')
Enter fullscreen mode Exit fullscreen mode

By using the * character, you can apply the active class to sub-menus easily:

routeIs('admin.cities*') ? 'active' : '' }}"> Cities
routeIs('admin.cities.index') ? 'active' : '' }}><a>List</a>
routeIs('admin.cities.create') ? 'active' : '' }}><a>Create</a>
Enter fullscreen mode Exit fullscreen mode

Top comments (0)