Laravel 8 在受保护的应用程序/模型中更改用户表名称不起作用

Ner*_*ull 2 php laravel laravel-fortify

我有一个相对较新的 laravel 8 安装与 jetstream/fortify。我正在尝试使用预先存在的用户表,该表的表名与默认的“用户”不同。

通过阅读周围的内容,我认为我必须在 app\Model\User.php 中更新它。我所做的如下:

 class User extends Authenticatable               
 14 {                                                                                                       
 15     /**                                                                                                                                                                                                
 16     .* My custom users table                        
 17     .*/
 18     protected $table = "user";  // note here it is user not users
 19     protected $primaryKey = "user_id";
Run Code Online (Sandbox Code Playgroud)

但是当我尝试注册新用户时,我收到 SQLSTATE 错误,指出未找到基表或视图......“mydb.users”不存在。

所以它仍然在寻找“用户”而不是“用户”。

我还需要在哪里更改此设置?

该文档似乎没有提到其他任何地方,其他堆栈答案似乎表明这应该足够了

编辑:这是我的 config/auth.php 部分

 67                                                                                         
 68     'providers' => [                                                                                 
 69     .   'users' => [                                               
 70     .   .   'driver' => 'eloquent',                                           
 71     .   .   'model' => App\Models\User::class,                                                                                  
 72     .   ],                                                                                                                                                                                                               
 73                    
 74     .   // 'users' => [                                               
 75     .   //     'driver' => 'database',                              
 76     .   //     'table' => 'users',                                               
 77     .   // ],                                                     
 78     ],     
Run Code Online (Sandbox Code Playgroud)

所以我相信我正在使用正确的用户提供者和雄辩。

N69*_*69S 7

电子邮件唯一性的验证规则将表名硬编码在其中(它发生在初始化任何模型之前,因此在某种程度上是有意义的)。

看起来像这样的东西

$validator = Validator::make($request->all(), [
    'email' => 'email|unique:users', //<- notice here that the database table name is hardcoded
    'password' => 'required',
]);
Run Code Online (Sandbox Code Playgroud)

如果您使用默认验证器,那么您需要复制它并更改该行。