我一直在使用laravel一段时间,但我偶然发现了一个我以前从未遇到过的错误。可能是我忽略了它,但是使用下面给出的路径文件,带有前缀帐号的路径组会给出一个空白页面。转到/account/anunregisteredroute
时,它会提供httpnotfoundexception
我的routes.php文件: http://pastebin.com/EnnGSm10
答案 0 :(得分:0)
通过在参数前添加/
,您可以解决此问题:
Route::get('/{username}', ['as' => 'account-profile', 'uses' => 'AccountController@getProfile']);
这段代码对我有用:
Route::group(['prefix' => 'account'], function () {
Route::get('/{username}', ['as' => 'account-profile', 'uses' => function($username){
echo $username;
}]);
Route::get('profile', ['as' => 'account-edit-profile', 'uses' => 'AccountController@getUpdate', 'before' => 'auth']);
Route::post('profile', ['as' => 'account-edit-profile', 'uses' => 'AccountController@postUpdate', 'before' => 'auth|csrf']);
Route::group(['before' => 'guest'], function () {
Route::get('create', ['as' => 'account-create', 'uses' => 'AccountController@getCreate']);
Route::get('signin', ['as' => 'account-signin', 'uses' => 'AccountController@getSignin']);
Route::group(['before' => 'csrf'], function() {
Route::post('create', ['as' => 'account-create', 'uses' => 'AccountController@postCreate']);
Route::post('signin', ['as' => 'account-signin', 'uses' => 'AccountController@postSignin']);
});
});
});
我得到了预期的输出。