Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to fix laravel routes?

Below are my routes, when I try to access /ranks/weekly, ranks/monthly and ranks/list it assume weekly, monthly & list as IDs and request data from GET /ranks/{id} show function.

Route::get('ranks', [RankingController::class, 'index']);
Route::post('ranks', [RankingController::class, 'create']);
Route::get('ranks/{ranking}', [RankingController::class, 'show']);
Route::put('ranks/{ranking}', [RankingController::class, 'update']);
Route::delete('ranks/{ranking}', [RankingController::class, 'destroy']);
Route::get('ranks/list', [RankingController::class, 'plain']);
Route::get('ranks/weekly', [RankingController::class, 'weekly']);
Route::get('ranks/monthly', [RankingController::class, 'monthly']);

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

So the reason for this is that:

Route::get('ranks/{ranking}', [RankingController::class, 'show']);

conflicts with everything succeeding ranks (i.e. weekly and monthly) because that matches with that route too. Like I stated in the comment, you can put the most lenient match at the bottom or be a little bit more restrictive in the matching for example:

Route::get('ranks/{ranking}', [RankingController::class, 'show'])->where('ranking', '[0-9]+');

Hope that helps!

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading