Request :: is()仅适用于父路由.如何在子路线上使用它? [英] Request::is() only work on parent route. How to use that on child route?

查看:24
本文介绍了Request :: is()仅适用于父路由.如何在子路线上使用它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用Request :: is()来打印一些引导程序类,但不幸的是,仅在父路由用户"上工作,但是当我在其子级中使用时,无法在用户/创建"上工作

i've tried using Request::is() for print some bootstrap class but unfortunately only work on parent route 'user', but when i using in their child not working 'user/create'

这是我的代码

<ul class="dropdown-menu">
     <li class="{{ Request::is('posts') ? 'active' : '' }}"><a class="nav-link" href="/posts">Posts</a></li>
     <li class="{{ Request::is('posts/create') ? 'active' : '' }}"><a class="nav-link" href="/posts/create">Create New</a></li>
</ul>

推荐答案

u可以尝试将(*)用于url之前或之后的任何路由:

u can try using (*) for any routes before or after url :

<ul class="dropdown-menu">
     //post/sub_url
     <li class="{{ Request::is('posts/*') ? 'active' : '' }}"><a class="nav-link" href="/posts">Posts</a></li>
     //match url
     <li class="{{ Request::is('posts/create') ? 'active' : '' }}"><a class="nav-link" href="/posts/create">Create New</a></li>
     //match any sub_url with any prefix
     <li class="{{ Request::is('*/posts/create/*') ? 'active' : '' }}"><a class="nav-link" href="/posts/create">Create New</a></li>
</ul>

这篇关于Request :: is()仅适用于父路由.如何在子路线上使用它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆