How to Add Classes to Active Link in Laravel

How to Add Classes to Active Link in Laravel

Adding a class to make the current page "active" in your application's navigation is a simple UI improvement. Let me show you how I typically do this in my apps.

Adding a class to make the current page "active" in your application's navigation is a simple UI improvement. Let me show you how I typically do this in my apps.

Generally speaking, the easiest way to do this is comparing the name of the current route and the one you'd like to test against.

Luckily, Laravel's Illuminate\Support\Facades\Route class provides a nice currentRouteName() method that we can use to make a comparison.

Let's create a little function that you can re-use throughout your application.

use Illuminate\Support\Facades\Route;

function active_route(string $name): bool
{
    return Route::currentRouteName() === $name;
}

This function is great, but it doesn't do anything with classes. Let's add a second parameter so that a class string such as 'bg-gray-900' could be passed through.

laravel

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Php how to delete multiple rows through checkbox using ajax in laravel

In this article i will let you know to delete multiple rows through checkbox using ajax in laravel and before delete we will give a confirmation message.

How to Hire Laravel Developers and How Much Does It Cost.

Want to make the most out of the latest Laravel technology? Here is your guide on how to hire the best Laravel developer, and at the right price. 

How to perform migration rollback in laravel

Sometimes we need to rollback one specific migration. Here, in this article we will discuss about the migration rollback in laravel.

Laravel Development Company

Skenix Infotech is a top Laravel Website Development Company with Expert Laravel Developers that provides robust Laravel Development Services at fair costs.

5 Laravel’s Hidden Gems

Spread the love1. Stop on first validation error By default, Laravel will check for all validation rules and return a list of errors. But if you want to stop this process after first validation failure, that’s how you can achieve…Read More→