Home > Software design >  Check if in header
Check if in header

Time:10-07

I have a check in the header, like if we are on the home page, then the link in the header is not active, and when on the other pages it is active, I also have a fixed-header class that I don't use yet.

The question is, how can I check that when we are on the home page, then the header is normal, and when on other pages the fixed-header class is assigned to the header, like this <header class = "header fixed-header">

php blade

<header class="header">
    @if (Route::currentRouteName() === 'home')
        <img class="header-logo" src="/img/logo.svg" alt="Go Interactive">
    @else
        <a href="{{ route('home') }}">
            <img class="header-logo" src="/img/logo.svg" alt="Go Interactive">
        </a>
    @endif
    <div class="header-menu">
        {{--<a href="#" class="header-menu__link">Blog</a>
        <a href="#" class="header-menu__link">Portfolio</a>
        <a href="#" class="header-menu__link">FAQ</a>--}}
        <a href="{{ route('contacts') }}" class="header-menu__link {{ (Route::currentRouteName() === 'contacts') ? 'active' : '' }}">Contacts</a>
    </div>

    <div class="mobile-menu-button">
        <img src="/img/menu_icon.svg" alt="">
    </div>
</header>

CodePudding user response:

If you have routenames then use: request()->routeIs('contact')

If you dont have routename then you can use: request()->is('contact')

In addition to the answear from Mainul Hasan.

<header class="header {{ request()->is('home') ? 'fixed-header' : ''  }}">...</header>

CodePudding user response:

Try this

<header class="header {{ Request::path() !=  'home' ? 'fixed-header' : ''  }}">

  • Related