Assuming you are in a blade file, you can leverage the routeIs()
method from the request()
helper.
The routeIs()
method can take one or multiple pattern to check so for example, lets say you have 2 routes:
user
user.role
so now we are on the user.role
route and in our blade file we are making the following check
request()->routeIs('user') //false
request()->routeIs('user.role') //true
request()->routeIs('user','user.role') //true - since the second is valid
request()->routeIs('user.*') //true - wildcard is accepted
Doc reference to the helper https://laravel.com/docs/8.x/requests#inspecting-the-request-path
I hope it can give you the tool to build your menu and the Active state
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…