php - Routes collision in Laravel 4
599
I am working on a project using Laravel 4, I have a "user route" to show user profiles by their username:
Route::get("user/{username}", array( 'as' => 'userProfile', 'uses' => '[email protected]') );
But here I have another route which shows a user's messages.
Route::get('user/messages', array( 'as' => 'userMessages', 'uses' => '[email protected]') )
But there is a collision here. Laravel thinks "messages" is a username because of first Route.
How can I work around this? Could some one help me, thanks.
Answer
Solution:
You must change the order of these Routes as Laravel processes them in the order they are defined in
routes.php
so,
comes before
And then in your
User
validation you must prevent anyone from choosing the usernamemessages