Php Laravel请求::is()-有更好的方法吗? @if(Request::is('login')、Request::is('tags')、Request::is('categories')、Request::is('posts')、Request::is('tages/.')、Request::is('categories/.')、Request::is('posts/{$post->id})或Request::is('posts/{$post->id}) @包括('partials.\u navAdmin') @否则 @包括('partials.\u nav') @恩迪夫

Php Laravel请求::is()-有更好的方法吗? @if(Request::is('login')、Request::is('tags')、Request::is('categories')、Request::is('posts')、Request::is('tages/.')、Request::is('categories/.')、Request::is('posts/{$post->id})或Request::is('posts/{$post->id}) @包括('partials.\u navAdmin') @否则 @包括('partials.\u nav') @恩迪夫,php,laravel,laravel-blade,laravel-request,Php,Laravel,Laravel Blade,Laravel Request,上面是我的main.blade.php文件中的一个示例;我正在尝试使用两个不同的导航栏-我知道有更好的方法来做到这一点,但我仍然无法掌握它 我认为反复重复Request::is不是好的编码标准。我是个新手:(我错过了什么?方法对参数进行迭代: foreach (func_get_args() as $pattern) { if (Str::is($pattern, $this->decodedPath())) { return true; } } 所以,像

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

我认为反复重复
Request::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}'))
为了 用户添加:- 请求::is('user/add')

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

感谢您的快速回复。这确实非常有用。