Laravel 5.2 身份验证将“id”更改为“customer_id”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34673901/
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 'id' to 'customer_id'
提问by Draity
In this topic I asked a question: Laravel 5.2 auth change 'users' table
在这个主题中,我问了一个问题:Laravel 5.2 auth change 'users' table
But now my problem has changed. By default the users table has an id
. But I want a customer_id
, so I changed everything but it don't work. It keeps asking for an id
.
但是现在我的问题已经改变了。默认情况下,用户表有一个id
. 但我想要一个customer_id
,所以我改变了一切,但它不起作用。它不断要求一个id
.
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'id' in 'where clause' (SQL: select * from
klanten
whereid
= 1 limit 1)
SQLSTATE[42S22]:未找到列:1054 'where 子句'中的未知列 'id'(SQL:select * from
klanten
whereid
= 1 limit 1)
In the table klanten
I have a customer_id
, but it keeps asking for an id
.
在表中klanten
我有一个customer_id
,但它一直要求一个id
.
Things I've changed:
我改变的事情:
config/auth
配置/认证
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\User::class,
'table' => 'klanten',
],
created a klanten
migration
创建了klanten
迁移
public function up()
{
Schema::create('klanten', function (Blueprint $table) {
$table->increments('klant_id');
$table->string('voornaam');
$table->string('email')->unique();
$table->string('password', 64);
$table->rememberToken();
$table->boolean('status');
$table->timestamps();
});
}
If I remove timestamps it keeps asking for created_at
and updated_at
too.
如果我删除时间戳它一直要求created_at
和updated_at
太。
Controllers/Auth/AuthController
控制器/身份验证/身份验证控制器
protected function validator(array $data)
{
return Validator::make($data, [
'voornaam' => 'required|max:255',
'email' => 'required|email|max:255|unique:klanten',
'password' => 'required|confirmed|min:6',
]);
}
protected function create(array $data)
{
return User::create([
'voornaam' => $data['voornaam'],
'email' => $data['email'],
'password' => bcrypt($data['password']),
]);
}
app/User
应用程序/用户
protected $table = 'klanten';
protected $fillable = [
'voornaam', 'email', 'password',
];
I hope somebody can help me!
我希望有人可以帮助我!
回答by ssuhat
edit your user model and add this:
编辑您的用户模型并添加以下内容:
protected $primaryKey = 'customer_id';
回答by Moppo
you can set the $primaryKey
filed in the User
model to specify the primary key of your table:
您可以$primaryKey
在User
模型中设置字段以指定表的主键:
protected $primaryKey = 'customer_id';