Laravel 5.3 new Auth:: routes()
Недавно я начал использовать laravel 5.3 для написания блога, но у меня возник вопрос после запуска php artisan make:auth
когда я запустил это, он будет генерировать маршруты в моем web.php
это код в нем:
Auth::routes();
Route::get('/home', '[email protected]');
Затем я запускаю php artisan route:list
, я нахожу много действий, таких как LoginController @login...
Но я не нашел эти действия в моем App\Http\Controllers\Auth
, где они?
А также что означает Auth::routes()
, я не могу найти маршруты об Auth.
Мне нужна помощь, спасибо вам ответить на мой вопрос
Ответы
Ответ 1
Auth::routes()
- это просто вспомогательный класс, который помогает вам генерировать все маршруты, необходимые для аутентификации пользователя. Вместо этого вы можете просмотреть код здесь https://github.com/laravel/framework/blob/5.3/src/Illuminate/Routing/Router.php.
Вот маршруты
// 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]');
$this->post('password/email', 'Auth\[email protected]');
$this->get('password/reset/{token}', 'Auth\[email protected]');
$this->post('password/reset', 'Auth\[email protected]');
Ответ 2
Атрибуты Auth для Laravel 5.3 вместо Auth:: routes().
Надеюсь, это поможет...
Route::group(['middleware' => ['web']], function() {
// Login Routes...
Route::get('login', ['as' => 'login', 'uses' => 'Auth\[email protected]']);
Route::post('login', ['as' => 'login.post', 'uses' => 'Auth\[email protected]']);
Route::post('logout', ['as' => 'logout', 'uses' => 'Auth\[email protected]']);
// Registration Routes...
Route::get('register', ['as' => 'register', 'uses' => 'Auth\[email protected]']);
Route::post('register', ['as' => 'register.post', 'uses' => 'Auth\[email protected]']);
// Password Reset Routes...
Route::get('password/reset', ['as' => 'password.reset', 'uses' => 'Auth\[email protected]']);
Route::post('password/email', ['as' => 'password.email', 'uses' => 'Auth\[email protected]']);
Route::get('password/reset/{token}', ['as' => 'password.reset.token', 'uses' => 'Auth\[email protected]']);
Route::post('password/reset', ['as' => 'password.reset.post', 'uses' => 'Auth\[email protected]']);
});
Итак, если вы измените некоторые имена этих маршрутов, не забудьте также изменить в представлениях действия сообщений!
Ответ 3
Здесь Laravel 5.7, Laravel 5.8 и Laravel 6.0 (одно незначительное изменение в 6.0 до маршрута проверки электронной почты), включая маршруты проверки, если вы хотите включить их.
// Authentication Routes...
Route::get('login', 'Auth\[email protected]')->name('login');
Route::post('login', 'Auth\[email protected]');
Route::post('logout', 'Auth\[email protected]')->name('logout');
// Registration Routes...
Route::get('register', 'Auth\[email protected]')->name('register');
Route::post('register', 'Auth\[email protected]');
// Password Reset Routes...
Route::get('password/reset', 'Auth\[email protected]')->name('password.request');
Route::post('password/email', 'Auth\[email protected]')->name('password.email');
Route::get('password/reset/{token}', 'Auth\[email protected]')->name('password.reset');
Route::post('password/reset', 'Auth\[email protected]')->name('password.update');
// Email Verification Routes...
Route::get('email/verify', 'Auth\[email protected]')->name('verification.notice');
Route::get('email/verify/{id}/{hash}', 'Auth\[email protected]')->name('verification.verify'); // v6.x
/* Route::get('email/verify/{id}', 'Auth\[email protected]')->name('verification.verify'); // v5.x */
Route::get('email/resend', 'Auth\[email protected]')->name('verification.resend');
Вы можете проверить эти маршруты здесь:
Ответ 4
Для Laravel 5.5.x
// 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]inkEmail')->name('password.email');
$this->get('password/reset/{token}', 'Auth\[email protected]')->name('password.reset');
$this->post('password/reset', 'Auth\[email protected]');
Ответ 5
вызов вызова функции:
- (Auth) Illuminate\Support\Facades\Auth @routes (https://github.com/laravel/framework/blob/5.3/src/Illuminate/Support/Facades/Auth.php)
- (App) Осветите \Foundation\Application @аутентификации
- (Маршрут) Осветите \Routing\Router
он прокладывает путь следующим образом:
public function auth()
{
// Authentication Routes...
$this->get('login', 'Auth\[email protected]');
$this->post('login', 'Auth\[email protected]');
$this->get('logout', 'Auth\[email protected]');
// Registration Routes...
$this->get('register', 'Auth\[email protected]');
$this->post('register', 'Auth\[email protected]');
// Password Reset Routes...
$this->get('password/reset/{token?}', 'Auth\[email protected]');
$this->post('password/email', 'Auth\[email protected]');
$this->post('password/reset', 'Auth\[email protected]');
}
Ответ 6
Это сработало для меня с Laravel 5.6.
В файле web.php
просто замените:
Auth::routes();
От:
//Auth::routes();
// Authentication Routes...
Route::get('admin/login', 'Auth\[email protected]')->name('login');
Route::post('admin/login', 'Auth\[email protected]');
Route::post('admin/logout', 'Auth\[email protected]')->name('logout');
// Password Reset Routes...
Route::get('password/reset', 'Auth\[email protected]')->name('password.request');
Route::post('password/email', 'Auth\[email protected]')->name('password.email');
Route::get('password/reset/{token}', 'Auth\[email protected]')->name('password.reset');
Route::post('password/reset', 'Auth\[email protected]');
И удалите ссылку Register в двух файлах ниже:
welcome.blade.php
layouts/app.blade.php
Ответ 7
класс loginuser использует признак AuthenticatesUsers
если вы откроете этот признак, вы увидите функции (это применимо для других контроллеров)
Illuminate\Foundation\Auth\AuthenticatesUsers;
вот код признака https://github.com/laravel/framework/blob/5.1/src/Illuminate/Foundation/Auth/AuthenticatesUsers.php
извините за плохой формат, im используя мой телефон
также Auth::routes()
он просто вызывает функцию, которая возвращает auth-маршруты, которые она (я думаю)
Ответ 8
Я удивлен, что никто не упомянул команду php artisan route:list
, которая выдает список всех зарегистрированных маршрутов приложений (включая Auth::routes()
и Passport::routes()
, если они зарегистрированы)