我想覆蓋/login
路由到/admin/login
。在web.php
我試過覆蓋Laravel 5.4中的默認Auth路由
//Auth::routes();
Route::get('login', ['as' => 'auth.login', 'uses' => 'App\Modules\Admin\Controllers\[email protected]'])->name('login');
但它仍然顯示Laravel默認登錄窗體。我怎樣才能做到這一點?
我想覆蓋/login
路由到/admin/login
。在web.php
我試過覆蓋Laravel 5.4中的默認Auth路由
//Auth::routes();
Route::get('login', ['as' => 'auth.login', 'uses' => 'App\Modules\Admin\Controllers\[email protected]'])->name('login');
但它仍然顯示Laravel默認登錄窗體。我怎樣才能做到這一點?
更改爲:
Route::get('/admin/login', ['as' => 'admin.login', 'uses' => 'App\Modules\Admin\Controllers\[email protected]']);
Route::get('login', ['as' => 'login', 'uses' => 'App\Modules\Admin\Controllers\[email protected]']);
name
功能是用於陣列的as
鍵的同義詞。所以最後不需要添加name
。
如果用戶嘗試/登錄會發生什麼? –
它會拋出一個'NotFoundHttpException'。 –
但我想覆蓋這條路線到'/ admin/login' –
對於Google員工,這裏是越來越受Auth::routes();
在Laravel 5.4
// Authentication Routes...
Route::get('login', [
'as' => 'login',
'uses' => 'Auth\[email protected]'
]);
Route::post('login', [
'as' => '',
'uses' => 'Auth\[email protected]'
]);
Route::post('logout', [
'as' => 'logout',
'uses' => 'Auth\[email protected]'
]);
// Password Reset Routes...
Route::post('password/email', [
'as' => 'password.email',
'uses' => 'Auth\[email protected]'
]);
Route::get('password/reset', [
'as' => 'password.request',
'uses' => 'Auth\[email protected]'
]);
Route::post('password/reset', [
'as' => '',
'uses' => 'Auth\[email protected]'
]);
Route::get('password/reset/{token}', [
'as' => 'password.reset',
'uses' => 'Auth\[email protected]'
]);
// Registration Routes...
Route::get('register', [
'as' => 'register',
'uses' => 'Auth\[email protected]'
]);
Route::post('register', [
'as' => '',
'uses' => 'Auth\[email protected]'
]);
php artisan route:list
產生將返回
+--------+----------+------------------------+------------------+------------------------------------------------------------------------+--------------+
| Domain | Method | URI | Name | Action | Middleware |
+--------+----------+------------------------+------------------+------------------------------------------------------------------------+--------------+
| | GET|HEAD | login | login | App\Http\Controllers\Auth\[email protected] | web,guest |
| | POST | login | | App\Http\Controllers\Auth\[email protected] | web,guest |
| | POST | logout | logout | App\Http\Controllers\Auth\[email protected] | web |
| | POST | password/email | password.email | App\Http\Controllers\Auth\[email protected] | web,guest |
| | GET|HEAD | password/reset | password.request | App\Http\Controllers\Auth\[email protected] | web,guest |
| | POST | password/reset | | App\Http\Controllers\Auth\[email protected] | web,guest |
| | GET|HEAD | password/reset/{token} | password.reset | App\Http\Controllers\Auth\[email protected] | web,guest |
| | GET|HEAD | register | register | App\Http\Controllers\Auth\[email protected] | web,guest |
| | POST | register | | App\Http\Controllers\Auth\[email protected] | web,guest |
+--------+----------+------------------------+------------------+------------------------------------------------------------------------+--------------+
你也可以試試這個路線的完整列表。
// Replace admin with whatever prefix you need
Route::group(['prefix' => 'admin'], function() {
Auth::routes();
});
您可以通過以下命令查看路由列表。
php artisan route:list
我不能感謝你,沒有這個讓我不得不開始重寫所有的路由,不僅如此,而且所有的LoginController方法都要覆蓋,路由也被重命名以避免混淆。我能夠使用這個前綴刪除我所有的自定義路由! – blamb
當我用同樣的問題所困擾我設法找到一個好辦法,覆蓋 laravel 5.5路線:
靜態功能驗證::路線(); :
public static function routes()
{
static::$app->make('router')->auth();
}
中的auth()函數在這裏稱爲它創建AUTH路線:
laravel /框架/ src目錄/照亮/路由/ Router.php
public function auth()
{
// Authentication Routes...
$this->get('login', 'Auth\[email protected]')->name('login');
$this->post('login', 'Auth\[email protected]');
$this->post('logout', 'Auth\[email protected]')->name('logout');
// Registration Routes...
$this->get('register', 'Auth\[email protected]')->name('register');
$this->post('register', 'Auth\[email protected]');
// Password Reset Routes...
$this->get('password/reset', 'Auth\[email protected]')->name('password.request');
$this->post('password/email', 'Auth\[email protected]')->name('password.email');
$this->get('password/reset/{token}', 'Auth\[email protected]')->name('password.reset');
$this->post('password/reset', 'Auth\[email protected]');
}
你可以複製&將功能正文粘貼到您的web.php中並根據需要進行修改。
只要記住,當你更新你的laravel應用程序時,這將全部重置。 – GabMic