Laravel 5.2 AUTH变化'身份证'到'CUSTOMER_ID“ [英] Laravel 5.2 auth change 'id' to 'customer_id'

查看:147
本文介绍了Laravel 5.2 AUTH变化'身份证'到'CUSTOMER_ID“的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在这个话题我问一个问题:<一href=\"http://stackoverflow.com/questions/34664087/laravel-5-2-auth-change-users-table/34664563#34664563\">laravel 5.2 AUTH变化用户表

In this topic I asked a question: laravel 5.2 auth change 'users' table

但现在我的问题已经改变。默认情况下,用户表有一个 ID 。但我希望有一个 CUSTOMER_ID ,所以我改变了这一切,但它不工作。它不断要求为 ID

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.

SQLSTATE [42S22]:列未发现:在1054年未知列'ID''where子句(SQL:SELECT * FROM klanten ,其中 ID = 1的限制1)

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'id' in 'where clause' (SQL: select * from klanten where id = 1 limit 1)

在表 klanten 我有一个 CUSTOMER_ID ,但它一直要求一个 ID

In the table klanten I have a customer_id, but it keeps asking for an id.

事情我已经改变了:

配置/ AUTH

'providers' => [
    'users' => [
        'driver' => 'eloquent',
        'model' => App\User::class,
        'table' => 'klanten',
    ],

创建一个 klanten 迁移

created a klanten migration

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();
    });
}

如果我删除时戳它一直要求 created_at 的updated_at 了。

If I remove timestamps it keeps asking for created_at and updated_at too.

控制器/认证/ 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']),
    ]);
}

应用/用户

protected $table = 'klanten';

protected $fillable = [
    'voornaam', 'email', 'password',
];

我希望有人能帮帮我!

I hope somebody can help me!

推荐答案

编辑您的用户模型,并补充一点:

edit your user model and add this:

protected $primaryKey = 'customer_id';

这篇关于Laravel 5.2 AUTH变化'身份证'到'CUSTOMER_ID“的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆