Search code examples
laravellaravel-5.3laravel-blade

Remove @include depending on the route


I have a menu partial, that includes a input search bar. But i don't want the search bar to be visibel on all pages, only for two specific uri´s. Is there a way to remove that include in blade?

Currently it looks like this:

<a href="{{ route('all') }}">all</a>
<a href="{{ route('nes') }}">nes</a>
<a href="{{ route('snes') }}">snes</a>
@include('partials._search')

I was thinking something like

<a href="{{ route('all') }}">all</a>
<a href="{{ route('nes') }}">nes</a>
<a href="{{ route('snes') }}">snes</a>
@if($url)
    @include('partials._search')
@endif

Solution

  • Use is() method:

    @if (request()->is($url))
        @include('partials._search')
    @endif
    

    Or if you know route name:

    @if (request()->route()->getName() === $routeName)
        @include('partials._search')
    @endif