Show a search input bar depending on which path the user currently is viewing I'm using Laravel with the Blade template engine. I'm trying to show a search input bar, depending on which path the user currently is viewing. The three paths are all, snes and nes.

This is what I have done so far:

@if (request()-&gt;route()-&gt;getName() === 'snes')
    @include('partials._search')
@endif

@if (request()-&gt;route()-&gt;getName() === 'nes')
    @include('partials._search')
@endif

@if (request()-&gt;route()-&gt;getName() === 'all')
    @include('partials._search')
@endif


It doesn't seem so effective nor like good looking code.

How can I shorten this?
You could use PHPs in_array() function to test the current route against your required routes:

@php ( $searchRoutes = ['foo', 'bar'] )
@if( in_array(request()-&gt;route()-&gt;getName(), $searchRoutes))
   @include('partials._search')
@endif


You could define the allowed routes array in your controller and pass this into the blade template.