更改Laravel身份验证表名称和列名称 [英] Changing Laravel auth table name and column names
问题描述
我想更改laravel auth表的表名和某些列名.
I want to change the table name and some column names of laravel auth table.
- 将表名从用户"更改为帐户"
- 将表列名从名称"更改为用户名"
- 将表列名从"email"更改为"email_addr"
- 将表列名从"updated_at"更改为"last_updated_at"
我应该采取什么步骤或在不破坏某些内容的情况下编辑哪些代码?
What steps do I take or which code do I edit without breaking something?
我以前尝试过此方法,并且注册有效,但登录没有成功.每当我尝试登录时,都会重定向回到登录页面.
I tried this before, and registration worked, but login didn't. Whenever I tried to log in, I got redirected back to the login page.
推荐答案
您可以按照以下给定步骤进行操作:
You can follow the below given steps:
- 创建/修改迁移,以将用户表更改为帐户
- 创建迁移以根据您对表帐户的要求更改列名称.确保此模型调用扩展了
Authenticatable
- 为帐户表创建模型类.
- 确保添加表的可填充和隐藏属性.
- 现在检查 login.blade.php 文件,并将
email
输入文本字段名称更改为email_address
.
- Create/modify migration to change the users table to accounts
- Create migration to change the column name as per your requirements for table accounts. Make sure this model call is extends
Authenticatable
- Create model class for accounts table.
- Make sure to add fillable and hidden attributes of table.
- Now check the login.blade.php file and change the
email
input text field name toemail_address
.
通过上述所有步骤,我们已经准备好查看部分,现在让我们开始自定义 Auth
With the above all steps, we are ready with View part now let's start with customising the Auth
-
现在打开 config/auth.php
- 从
'model'=>更改;App \ User :: class,
到'model'=>
提供程序数组中的App \ Account:class .
- Change from
'model' => App\User::class,
to'model' => App\Account:class
insideproviders
array.
现在,我们需要在 app/Http/Auth/LoginController.php 中添加新功能,如下所示:
Now we need to add new function inside app/Http/Auth/LoginController.php like below:
公共函数username(){返回'email_address';//此字符串是帐户表的列,我们将用于登录}
现在我们完成所有调整,您可以测试功能.
Now we are done with all adjustment, you can test the functionality.
我已经测试了该功能及其功能,就像魅力一样:)
I have tested the functionality and its working like charm :)
这篇关于更改Laravel身份验证表名称和列名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!