How to Check If Current Page is Home Page in Laravel

The Laravel homepage is the main page of a website or web application made with the Laravel Framework. It is the first page that a user sees when visiting the website. The homepage usually contains the main navigation menu, a search bar, and a few featured items.

There are times when you need to check if the current page is the home page, for example, to add a class “active” to the home page menu item.

In Laravel, this can be done using the Request::is method or route check.

//in view
{!! Request::is('/') ? '' : url('/') !!}

//define route name in route file then check with getName() method in view
Route::get('/', ['as'=>'homepage', 'uses'=>'[email protected]']);

@if(request()->route()->getName() == 'homepage')

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.