Laravel Request::is() - 有更好的方法吗?

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

以上是我的 main.blade.php 文件中的示例;我正在尝试使用 2 个不同的导航栏 - 我知道有更好的方法可以做到这一点,但我仍然无法掌握它!

我认为一遍又一遍地重复 Request::is 并不是好的编码标准。我是新手:(我错过了什么?

is() 方法遍历参数:

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

所以,像这样的东西应该适合你:

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

为了 用户添加:- Request::is('user/add');

用户编辑:- Request::is('user//edit'); Request::is('user/edit/');