Masume Ebhami
Masume Ebhami

Reputation: 348

404 error in Laravel routing with changing parameter order

There is a strange problem in my Laravel routing. When I use this url everything goes perfect:

Route::get('properties/{product}', 'ProController@getpro');

But while I want to change the order like below, I get a 404 not found page:

Route::get('{product}/properties', 'ProController@getpro');

What is the problem?

http://127.0.0.1:8000/product/pizza-lake-dariusbury/properties 404 (Not Found)

I'm using Laravel installer version 2.0.1

Upvotes: 1

Views: 392

Answers (1)

Laerte
Laerte

Reputation: 7083

Since you are using two routes that take generic parameters, Laravel could have problem to match a URL to a route. For example: /product/1/properties, could perfectly fit this {prod?}/{prod_size?}.

To fix this, I suggest that you add some prefix to the route, to identify them:

Route::get('routename1/{product}/properties', 'ProController@getpro');
Route::get('routename2/{prod?}/{prod_size?}', 'ProController@name');

Then routename1/1/properties would never fit routename2/{prod?}/{prod_size?}.

Then Laravel would be able to match perfectly the URL parameters to the route.

Upvotes: 2

Related Questions