Search code examples
phplaravellaravel-5

Using Route::is() to check if the route is the homepage


How can i check to see if the current route is the root page?

i've tried in a blade file typing thie following:

@if(Route::is('/')
//show something
@else 
//show something else
@endif

i've also tried it with Route::currentRouteName() such as

@if(Route::currentRouteName() == '/')
//do something
@else
//do something else
@endif

and it doesn't seem to work on the root page. is there an alternative way? or is it that the root doesn't have a route?


Solution

  • @if(Request::is('/'))
      //do something
    @else
      //do something
    @endif