问题
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