문제

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' => 'UserController@getProfile') );

But here I have another route which shows a user's messages.

Route::get('user/messages', array( 'as' => 'userMessages', 'uses' => 'MessageController@getMessages') )

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.

도움이 되었습니까?

해결책

You must change the order of these Routes as Laravel processes them in the order they are defined in routes.php

so,

Route::get('user/messages', array( 'as' => 'userMessages', 'uses' => 'MessageController@getMessages') )

comes before

Route::get("user/{username}", array( 'as' => 'userProfile', 'uses' => 'UserController@getProfile') );

And then in your User validation you must prevent anyone from choosing the username messages

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top