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
JavaScript
x
Route::get('products','abcontroller@index');
Route::get('product/{name}','abcontroller@searchProduct');
now if i used the following code:
JavaScript
@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
JavaScript
Route::get('products',['as' => 'product.index', 'uses' => 'abcontroller@index']);
Route::get('product/{name}',['as' => 'product.name', 'uses' => 'abcontroller@searchProduct']);
use
JavaScript
@if(Route::is('product.*')
// something print
@endif
Hope can help you