Search code examples
phplaravellaravel-routing

Laravel how to get current Route


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


Solution

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