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

vah*_*ian 10 php laravel

@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')
Run Code Online (Sandbox Code Playgroud)

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

我不认为重复Request ::是一遍又一遍的好编码标准.我是新手:(那边我想念的是什么?

Ale*_*nin 18

is() 方法迭代参数:

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

所以,这样的事情对你有用:

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