Skip to content
Advertisement

Laravel : How to check dynamic url using Request::path()

I was trying to show a search box based on url means for specific route it will show the search box otherwise it won’t show. for that i used Request::path() . But the problem is for some route it doesn’t work. Suppose i have two routes, such as

Route::get('products','abcontroller@index');
Route::get('product/{name}','abcontroller@searchProduct');

now if i used the following code:

@if(Request::path() == 'products' || Request::path() == 'product/{name}')
  // something print
@endif

For the products route i could see the search Box but for product/{name} I couldn’t .. How do i solve the issue?

Advertisement

Answer

Route::get('products',['as' => 'product.index', 'uses' => 'abcontroller@index']);
Route::get('product/{name}',['as' => 'product.name', 'uses' => 'abcontroller@searchProduct']);

use

@if(Route::is('product.*')
// something print
@endif

Hope can help you

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement