Laravel how to get current Route

与世无争的帅哥 提交于 2020-12-27 03:14:35

问题


I have the following in my Routes.php:

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

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} 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.

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


回答1:


You can use Request::is('cat/a').




回答2:


You can get {cat} part with this:

$cat = Request::route()->getParameter('cat');

And the route with:

$route = Route::currentRouteName();


来源:https://stackoverflow.com/questions/36578911/laravel-how-to-get-current-route

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!