Laravel 5.2 身份验证更改“用户”表
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34664087/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel 5.2 auth change 'users' table
提问by Draity
I used the new feature in Laravel:
我在 Laravel 中使用了新功能:
php artisan make:auth
But when I register it will use the database table users
by default, but I want to change that to an other table. And by default it uses updated_at
and created_at
in that table, I want to remove that too.
但是当我注册时它会users
默认使用数据库表,但我想将其更改为其他表。默认情况下,它使用updated_at
并且created_at
在该表中,我也想删除它。
Auth/AuthController
身份验证/身份验证控制器
protected function create(array $data)
{
return User::create([
'voornaam' => $data['voornaam'],
'email' => $data['email'],
'password' => bcrypt($data['password']),
]);
}
app\User
应用\用户
protected $fillable = [
'voornaam', 'email', 'password',
];
This are the things I thought would change it, but they didn't. I hope somebody can tell me some more about this issue.
这是我认为会改变它的事情,但他们没有。我希望有人能告诉我更多关于这个问题的信息。
回答by Marcin Nabia?ek
To change table name go to app/User.php
and set property $table
to custom one for example:
要更改表名,请转到app/User.php
并将属性设置$table
为自定义,例如:
$table = 'new_table';
You should also change default migration. Go to: /database/migrations/2014_10_12_000000_create_users_table.php
file and change users
here for the same name. To remove timestamps you can remove line:
您还应该更改默认迁移。转到:/database/migrations/2014_10_12_000000_create_users_table.php
文件并users
在此处更改为相同的名称。要删除时间戳,您可以删除行:
$table->timestamps();
however if I were you I would reconsider removing those timestamps
但是,如果我是你,我会重新考虑删除这些时间戳
回答by Elnur Ibrahim-zade
DO NOT FORGET TO CHANGE VALIDATION IN REGISTERCONTOLLER.PHP AS WELL.
不要忘记更改 REGISTERCONTOLLER.PHP 中的验证。
from
从
'email' => 'required|email|max:255|unique:users',
to
到
'email' => 'required|email|max:255|unique:company',
回答by Abdul Manan
By default model take its class name as table name !
I define a protected property at the top of App/User.php
默认情况下,模型将其类名作为表名!
我在顶部定义了一个受保护的属性App/User.php
protected $table = 'auth_users';
This tells laravel to use auth_users
table instead of default user
table.
and it works like charm.
这告诉 laravel 使用auth_users
table 而不是默认user
table。它的作用就像魅力一样。
回答by Koeffi
Check Laravel 5.3 Change user table in Authfor an alternative solution, using modification in config/auth.php and RegisterController.php.
检查Laravel 5.3 Change user table in Auth以获取替代解决方案,使用 config/auth.php 和 RegisterController.php 中的修改。
To disable the timestamps you may also use in the model class:
要禁用时间戳,您也可以在模型类中使用:
public $timestamps = false;