Two ways to check the route name

Here are two ways to check the route name in Laravel.

1// #1
2<a
3 href="{{ route('home') }}"
4 @class="['navbar-link', 'active' => Route::current()->getName() === 'home']"
5>
6 Home
7</a>
8// #2
9<a
10 href="{{ route('home') }}"
11 @class="['navbar-link', 'active' => request()->routeIs('home)]"
12>
13 Home
14</a>

Tip given by @AndrewSavetchuk

Like our articles?

Become a Premium Member for $129/year or $29/month
What else you will get:
  • 22 courses (477 lessons, total 38 h 20 min)
  • 2 long-form tutorials (one new every week)
  • access to project repositories
  • access to private Discord