我有一个奇怪的问题,而不是我完全不理解......
这是我的路线:
Route::get('/app/signin', array( 'as' => 'account-login', 'uses' => 'AccountController@getLogin' ));
哪个效果很好。但是,当我松开/ app部分时,我收到错误。如果我将其更改为
Route::get('/signin', array( 'as' => 'account-login', 'uses' => 'AccountController@getLogin' ));
我收到以下错误:
* @throws \Symfony\Component\HttpKernel\Exception\HttpException
* @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
*/
public function abort($code, $message = '', array $headers = array())
{
if ($code == 404)
{
throw new NotFoundHttpException($message);
}
else
非常感谢任何帮助
**更新1 **
以下是我的完整路线列表:
// ALL PUBLIC ACCESS ROUTES
Route::get('/', array( 'as' => 'home', 'uses' => 'HomeController@home' ));
Route::get('/{username}', array( 'as' => 'profile-user', 'uses' => 'ProfileController@user' ));
// UNAUTHENTICATED GROUP (GUEST - PUBLIC ACCESS WITH FORMS AND SIGNUP)
Route::group(array('before' => 'csrf'), function() {
Route::post('/app/create', array( 'as' => 'account-create-post', 'uses' => 'AccountController@postCreate' ));
Route::post('/app/login', array( 'as' => 'account-login-post', 'uses' => 'AccountController@postLogin' ));
Route::post('/app/forgot-password', array( 'as' => 'account-forgot-password-post', 'uses' => 'AccountController@postForgotPassword' ));
});
Route::get('/app/forgot-password', array( 'as' => 'account-forgot-password', 'uses' => 'AccountController@getForgotPassword' ));
Route::get('/app/recover{code}', array( 'as' => 'account-recover', 'uses' => 'AccountController@getRecover' ));
Route::get('/app/signin', array( 'as' => 'account-login', 'uses' => 'AccountController@getLogin' ));
Route::get('/app/create', array( 'as' => 'account-create', 'uses' => 'AccountController@getCreate' ));
Route::get('/app/activate/{code}', array( 'as' => 'account-activate', 'uses' => 'AccountController@getActivate' ));
// AUTHENTICATED GROUP (WHEN USER IS LOGGED IN)
Route::group(array('prefix' => 'app', 'before' => 'auth'), function() {
Route::group(array('before' => 'csrf'), function() {
Route::post('/change-password', array( 'as' => 'account-change-password-post', 'uses' => 'AccountController@postChangePassword' ));
});
Route::get('/change-password', array( 'as' => 'account-change-password', 'uses' => 'AccountController@getChangePassword' ));
Route::get('/signout', array( 'as' => 'account-sign-out', 'uses' => 'AccountController@getSignOut' ));
});
答案 0 :(得分:3)
Route::get('/{username}', array( 'as' => 'profile-user', 'uses' => 'ProfileController@user' ));
问题是,我建议澄清这条路线,先添加一些东西,或者把它放在路线的底部,这样其他定义的单字路线就会先找到它们各自的路径控制器。
建议插入正则表达式(根据需要进行修改)
Route::pattern('username', '[a-z]+')
在该路线之前或使用像这样的where
子句
Roue::get( /* username */ )->where('username', '[a-z]+');
这种方法应该用在每个路由参数上,以便更好地控制路由和数据操作。
旁注
阻止用户拥有其他单词路由的用户名,因为用户@BarryWalsh建议无法访问这些路由。
答案 1 :(得分:0)
这看起来确实很奇怪,但作为一个开始,我试着看看是否从目标URI中删除了前面的斜线(因此'/ signin'变为'signin')修复了问题,因为这些不是必需的。