Route::auth() 和命名空间
Route::auth() and namespacing
我已经使用 make:auth
创建了在基本应用程序中运行良好的登录脚手架。但是,我正在创建一个包,因此我已将文件移动到包中它们各自的位置。
我已将 make:auth
应用程序创建的路由命名空间命名为
Route::group(['middleware' => 'web'], function () {
Route::auth();
Route::get('/home', 'Package\Namespace\HomeController@index');
});
当我注释掉 Route::auth();
时,一切似乎都正常。当我保持 Route::auth
时,我得到一个错误
Class Auth\AuthController does not exist
我不明白这是什么问题。我不太了解 auth()
辅助函数。
明显错误...
在 Router.php
中,auth()
函数命名空间与默认的 Controllers
命名空间有关。
删除 auth()
函数并将所有命名空间路由添加到路由文件中当然可以解决问题
// Authentication Routes...
Route::get('login', 'App\Http\Controllers\Auth\AuthController@showLoginForm');
Route::post('login', 'App\Http\Controllers\Auth\AuthController@login');
Route::get('logout', 'App\Http\Controllers\Auth\AuthController@logout');
// Registration Routes...
Route::get('register', 'App\Http\Controllers\Auth\AuthController@showRegistrationForm');
Route::post('register', 'App\Http\Controllers\Auth\AuthController@register');
// Password Reset Routes...
Route::get('password/reset/{token?}', 'App\Http\Controllers\Auth\PasswordController@showResetForm');
Route::post('password/email', 'App\Http\Controllers\Auth\PasswordController@sendResetLinkEmail');
Route::post('password/reset', 'App\Http\Controllers\Auth\PasswordController@reset');
我已经使用 make:auth
创建了在基本应用程序中运行良好的登录脚手架。但是,我正在创建一个包,因此我已将文件移动到包中它们各自的位置。
我已将 make:auth
应用程序创建的路由命名空间命名为
Route::group(['middleware' => 'web'], function () {
Route::auth();
Route::get('/home', 'Package\Namespace\HomeController@index');
});
当我注释掉 Route::auth();
时,一切似乎都正常。当我保持 Route::auth
时,我得到一个错误
Class Auth\AuthController does not exist
我不明白这是什么问题。我不太了解 auth()
辅助函数。
明显错误...
在 Router.php
中,auth()
函数命名空间与默认的 Controllers
命名空间有关。
删除 auth()
函数并将所有命名空间路由添加到路由文件中当然可以解决问题
// Authentication Routes...
Route::get('login', 'App\Http\Controllers\Auth\AuthController@showLoginForm');
Route::post('login', 'App\Http\Controllers\Auth\AuthController@login');
Route::get('logout', 'App\Http\Controllers\Auth\AuthController@logout');
// Registration Routes...
Route::get('register', 'App\Http\Controllers\Auth\AuthController@showRegistrationForm');
Route::post('register', 'App\Http\Controllers\Auth\AuthController@register');
// Password Reset Routes...
Route::get('password/reset/{token?}', 'App\Http\Controllers\Auth\PasswordController@showResetForm');
Route::post('password/email', 'App\Http\Controllers\Auth\PasswordController@sendResetLinkEmail');
Route::post('password/reset', 'App\Http\Controllers\Auth\PasswordController@reset');