Styling active route menu item in laravel

James Bhatta
May 14, 2021

--

You can check if the current route is active just with

request()->routeIs('admin.cities')

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

request()->routeIs('admin.cities*')

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

Route::named('admin.cities*')

By using the * character, you can apply the active class to submenus easily:

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

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

James Bhatta
James Bhatta

Written by James Bhatta

Manoj Bhatta. PHP developer often working in Laravel. Loved PHP just because I cant wait until compiler processes my code.

No responses yet

Write a response