16
@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?

kjones
  • 1,339
  • 1
  • 13
  • 28
vahan terzibashian
  • 258
  • 1
  • 4
  • 9

2 Answers2

39

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}'))
Alexey Mezenin
  • 158,981
  • 26
  • 290
  • 279
1

For User Add :- Request::is('user/add');

User Edit :- Request::is('user//edit'); Request::is('user/edit/');