gpt4 book ai didi

php - Laravel auth 在登录前检查列

转载 作者:可可西里 更新时间:2023-11-01 13:49:11 25 4
gpt4 key购买 nike

我正在使用 Laravel 5.4 及其内置的 Auth API。我在 users 表中添加了一列,名为 is_admin。我想修改登录过程,以便登录仅在 is_admin == 1 时有效。我查看了 Illuminate\Foundation\Auth\AuthenticatesUsers.php ( Github ),我可能会在那里进行更改,但我宁愿尽可能不打扰核心。有没有更优雅的方法来做到这一点?

最佳答案

我用类似于@Sagar Arora 的解决方案解决了这个问题。在运行 artisan make:auth 时创建的 app\Http\Controllers\Auth\LoginController.php 中,我覆盖了 attemptLogin 方法来自 AuthenticatesUsers。这是 LoginController.php 中的代码:

protected function attemptLogin(Request $request)
{
return (auth()->attempt(['email' => $request->email, 'password' => $request->password, 'is_admin' => 1]));
}

现在只有具有 is_admin == 1 的用户才能登录。

关于php - Laravel auth 在登录前检查列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42395540/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com