Laravel Request::is() - is there a better way?

vahan terzibashian picture vahan terzibashian · Nov 26, 2016 · Viewed 18k times · Source
@if(Request::is('login') OR Request::is('tags') OR Request::is('categories') OR Request::is('posts') OR Request::is('tags/..') OR Request::is('categories/..') OR Request::is('posts/..') OR Request::is("posts/{$post->id}"))
    @include('partials._navAdmin')
@else  
    @include('partials._nav')
@endif

Above is an example in my main.blade.php file; I am trying to use 2 different navigation bars - I know there is a better way to do this but I still can't get the grasp of it!

I don't think it is good coding standards to repeat Request::is over and over again. I am a newbie :( what did I miss over there?

Answer

Alexey Mezenin picture Alexey Mezenin · Nov 26, 2016

is() method iterates over arguments:

foreach (func_get_args() as $pattern) {
    if (Str::is($pattern, $this->decodedPath())) {
        return true;
    }
}

So, something like this should work for you:

@if(Request::is('login', 'tags', 'categories', 'posts', 'tags/..', 'categories/..', 'posts/..', 'posts/{$post->id}'))