Подтвердить что ты не робот

Переопределение маршрутов Auth по умолчанию в Laravel 5.4

Я хочу переопределить /login маршрут /admin/login. В web.php я попробовал

//Auth::routes();
Route::get('login', ['as' => 'auth.login', 'uses' => 'App\Modules\Admin\Controllers\[email protected]'])->name('login');

Но по-прежнему отображается форма входа в Laravel по умолчанию. Как я могу это сделать?

4b9b3361

Ответ 1

Для googlers, вот полный список маршрутов, которые генерируются 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' => 'password.update',
  '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         | password.update  | 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    |
+--------+----------+------------------------+------------------+------------------------------------------------------------------------+--------------+

Ответ 2

Вы также можете попробовать это.

// Replace admin with whatever prefix you need

Route::group(['prefix' => 'admin'], function () {

    Auth::routes();

});

Вы можете просмотреть список маршрутов по следующей команде.

php artisan route:list

enter image description here

Ответ 3

Маршруты для 5.5 LTS (подтверждено)/5.6 (подтверждено)/5.7 (?)

Может ли кто-то подтвердить, что он работает с 5.7?

// 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]');

Ответ 4

Поскольку я боролся с той же проблемой, мне удалось найти хороший способ переопределить маршруты laravel 5.5:

Статическая функция Auth :: routes(); :

public static function routes()
{
    static::$app->make('router')->auth();
}

Здесь вызывается функция auth(), которая создает auth-маршруты:

Laravel/рамки /SRC/Осветите /Routing/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 и изменить их по своему усмотрению.

Ответ 5

Вы можете найти все маршруты входа в Laravel 5.7. Есть что-то новое, проверка электронной почты. Связанная документация находится здесь.

Если инструкции в блоке кода в основном включают/отключают функции auth. Используя хелпер, вы можете передать register, reset, verify параметры на Auth::routes(['verify' => true]); , Так что исправьте if statements с помощью config() или просто используйте по своему усмотрению.

Завершите здесь!
Когда вы вызываете Auth::routes(), будут зарегистрированы следующие маршруты.

Route::get('login', '[email protected]')->name('login');
Route::post('login', '[email protected]');
Route::post('logout', '[email protected]')->name('logout');

// Registration Routes...
if (config('register'))
{
    Route::get('register', '[email protected]')->name('register');
    Route::post('register', '[email protected]');
}
// Password Reset Routes...
if (config('reset'))
{
    Route::get('password/reset', '[email protected]')->name('password.request');
    Route::post('password/email', '[email protected]')->name('password.email');
    Route::get('password/reset/{token}', '[email protected]')->name('password.reset');
    Route::post('password/reset', '[email protected]')->name('password.update');
}
// Email Verification Routes...
if (config('verify'))
{
    Route::get('email/verify', '[email protected]')->name('verification.notice');
    Route::get('email/verify/{id}', '[email protected]')->name('verification.verify');
    Route::get('email/resend', '[email protected]')->name('verification.resend');
}

Ответ 6

Измените это на:

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 в конце.

Ответ 7

Я подготовил всеобъемлющий учебник для Auth :: routs() в Laravel 5.7 ad 5.8.

Я надеюсь, что это полезно.

Эта ссылка