Laravel如何获得当前路线 [英] Laravel how to get current Route

查看:43
本文介绍了Laravel如何获得当前路线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Routes.php中包含以下内容:

I have the following in my Routes.php:

Route::get('cat/{cat}', ['as' => 'cat', 'uses' => 'CatController@get']);

我想在我的sidebar.blade.php文件中检查从Controller函数返回的任何视图是否与当前页面匹配.

I want to check in my sidebar.blade.php file if any of the views returned from the Controller function matches the current page.

{cat} 可以是a,b,c,d,f或e.侧边栏包含6张图片.例如,如果路线为 cat/a ,则应更改tis路线的图像.

{cat} could be either a,b,c,d,f or e. The sidebar consists of 6 images. If for example the route is cat/a the image of tis route should be changed.

人们建议使用 Route :: current()-> getName(),但这只会返回 cat ,而不返回/a,/b,/c等.其他一些函数只返回 cat/,此后什么也没有返回

People suggested Route::current()->getName() but this only returns cat and not /a, /b, /c, etc. Also some other functions are only returning cat/ and nothing after that

推荐答案

您可以使用 Request :: is('cat/a').

这篇关于Laravel如何获得当前路线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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