在 Laravel 8 中禁用身份验证注册路由?

Deb*_*ury 8 php laravel laravel-8

我需要在 Laravel 8 中禁用我的注册路由。试过

Auth::routes([
     'register' => false,
     'login' => false,
]);
Run Code Online (Sandbox Code Playgroud)

但是应用程序抛出了一个错误。

RuntimeException
In order to use the Auth::routes() method, please install the laravel/ui package.
Run Code Online (Sandbox Code Playgroud)

如果有人指出需要改变的地方,将不胜感激。

谢谢

sta*_*sta 16

Laravel 8 使用强化身份验证。要从您的 Laravel 应用程序禁用注册,您需要从fortify禁用它,它位于/config/fortify.php

'features' => [
    // Features::registration(), // disable here
     Features::resetPasswords(),
     Features::emailVerification(),
     Features::updateProfileInformation(),
     Features::updatePasswords(),
     Features::twoFactorAuthentication(),
],
Run Code Online (Sandbox Code Playgroud)

  • 我有 Laravel 8.x 并且没有 config/fortify.php 类。也不是那个数组。 (2认同)

小智 7

另外,请务必禁用相关路由,在routes/web.php

Route::get('/register', function() {
    return redirect('/login');
});

Route::post('/register', function() {
    return redirect('/login');
});
Run Code Online (Sandbox Code Playgroud)

我根据功能测试进行了更改,tests/Feature/RegistrationTest.php以尽量保持工作干净,因此我需要这些重定向。


cak*_*kan 5

在我的末尾routes/web.php是以下行:

require __DIR__.'/auth.php';
Run Code Online (Sandbox Code Playgroud)

routes/auth.php列出了用户登录/注册/注销的所有附加的路由。只需注释掉或/register从那里删除路线。