Pergunta

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.

Foi útil?

Solução

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

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top