Last active
July 18, 2019 20:18
-
-
Save zrhoffman/91a5d9a0f03c75781fe4933409537240 to your computer and use it in GitHub Desktop.
Laravel route collision problem
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Illuminate\Support\Facades\Route; | |
/* | |
* Routes: | |
* second/fifth | |
* third/sixth | |
* | |
* ./artisan route:list | |
* +--------+----------+----------------------------+------+---------+--------------+ | |
* | Domain | Method | URI | Name | Action | Middleware | | |
* +--------+----------+----------------------------+------+---------+--------------+ | |
* | | GET|HEAD | api/user | | Closure | api,auth:api | | |
* | | GET|HEAD | {group}/{page} | | Closure | web | | |
* | | GET|HEAD | {group}/{page}/{optional?} | | Closure | web | | |
* +--------+----------+----------------------------+------+---------+--------------+ | |
*/ | |
Route::prefix('{group}')->where(['group' => 'first'])->group(function () { | |
Route::get('{page}', function () { | |
return 'This page will 404.'; | |
})->where(['page' => 'fourth']); | |
}); | |
Route::prefix('{group}')->where(['group' => 'second'])->group(function () { | |
Route::get('{page}', function (string $group, string $page) { | |
return "This is the {$page} page in the {$group} group.<br>In a larger project, this route would go to Controller2."; | |
})->where(['page' => 'fifth']); | |
}); | |
Route::prefix('{group}')->where(['group' => 'third'])->group(function () { | |
Route::get('{page}/{optional?}', function (string $group, string $page) { | |
return "This is the {$page} page in the {$group} group.<br>In a larger project, this route would go to Controller3."; | |
})->where(['page' => 'sixth', 'optional' => 'A string no one will guess']); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment