Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Laravel - Navigation Active Class
<!-- Example on how to set class="active" on active navigation links -->
<!-- These links will always be visible -->
<li class="{{ URI::is( 'home') ? 'active' : '' }}">
<a href="{{ URL::to( 'home') }}">
Home
</a>
</li>
<li class="{{ URI::is( 'gallery') ? 'active' : '' }}">
<a href="{{ URL::to( 'gallery') }}">
Gallery
</a>
</li>
<!-- Show link to 'account' if authed -->
@if ( Auth::check() )
<li class="{{ URI::is( 'account') ? 'active' : '' }}">
<a href="{{ URL::to( 'account') }}">
Account
</a>
</li>
@endif
<!-- Login/Logout depending on auth state -->
<li class="{{ URI::is( 'account/login') ? 'active' : '' }}">
@if ( Auth::guest() )
{{ HTML::link('account/login', 'Login') }}
@else
{{ HTML::link('account/logout', 'Logout') }}
@endif
</li>
@kampit

This comment has been minimized.

Copy link

commented Feb 12, 2014

Use Request::is() instead of URI::is()

@miftahafina

This comment has been minimized.

Copy link

commented Mar 6, 2015

@daniel and @kampit, thanks.

@MarceloH

This comment has been minimized.

Copy link

commented May 19, 2015

Good!! Thanks for help.

@arifulhb

This comment has been minimized.

Copy link

commented Jun 4, 2015

Thanks.. It helped :) Also thanks to @kampit for Request::is()

@lawrence34

This comment has been minimized.

Copy link

commented Jun 21, 2015

thanks man!

@ManojKiranA

This comment has been minimized.

@jscalderons

This comment has been minimized.

Copy link

commented Feb 6, 2019

In case of multilevel, use (En caso de multinivel, usar): Request::is('[level]', '[level]/*');

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.