vahan terzibashian vahan terzibashian - 6 days ago 7
PHP Question

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

@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')


here is an example in my main.blade.php file, now what I'm doing is that 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

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}'))
Comments