Laravel 5: Setting bootstrap active navbar links

There are several ways in adding ‘active’ navbar class to your Bootstrap navigation bar. This means that when you click to any of your navigation menu, the active state will also be on the page where you are on.

I’ll share MY way of doing it and I find it simple and not having problem at all (unless you have super multi-level navigation bar). Bootstrap has ‘active’ class that allows user to see which pages he is on. This serves as page indicator as well.

Laravel 5: bootstrap active navbar links

Doing active navbar in Laravel is easy, you just have to identify the segment of your page. Like the image below.

Laravel 5: bootstrap active navbar links

The Request::segment(1) === ‘about’ is the first segment of your application. This means that the number of segment will based on how many slashes you have.
@if(Auth::check()) Checks whether the user is logged in. And if logged-in it will change the login link to ‘Dashboard’.

Hope that this helps you solve the active navbar in your page.

pretty cool!

Sharing is caring!