kunal
kunal

Reputation: 253

How to improve laravel routing?

I am working on some ecommerce project in laravel framework where my category route is below:-

Route::get('/category/{catname}', 'SearchController@searchCatProducts');

When i access website its working like this:-

www.example.com/category/men

But our client wants it should like this :-

www.example.com/men

if i create Roue like:-

Route::get('/{catname}', 'SearchController@searchCatProducts');
and other routes will also reflect like aboutus, contactus,
Route::get('/aboutus', 'CMScontroller@aboutus');

Can anyone help me. Thanks in advance.

Upvotes: 1

Views: 361

Answers (2)

Ali Özen
Ali Özen

Reputation: 1609

You must change the order.

Route::get('/aboutus', 'CMScontroller@aboutus');
Route::get('/{catname}', 'SearchController@searchCatProducts');

put the static routes to the top. dynamic route to the bottom.

Upvotes: 1

user10186369
user10186369

Reputation:

You should try this:

Route::get('/{catname}', 'SearchController@searchCatProducts');

Route::get('/frontend/aboutus', 'CMScontroller@aboutus');
Route::get('/frontend/contactus', 'CMScontroller@contactus');

Upvotes: 0

Related Questions