Laravel 5.2 auth将'id'更改为'customer_id'

时间:2016-01-08 09:47:11

标签: laravel authentication laravel-5 laravel-5.2

在这个主题中,我问了一个问题:Laravel 5.2 auth change 'users' table

但现在我的问题已经改变了。默认情况下,users表具有id。但我想要一个customer_id,所以我改变了一切,但它不起作用。它不断要求id

  

SQLSTATE [42S22]:未找到列:1054'where子句'中的未知列'id'(SQL:select * from klanten其中id = 1 limit 1)

在表klanten中我有一个customer_id,但它一直要求id

我改变的事情:

配置/ AUTH

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

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

如果删除时间戳,它会不断要求created_atupdated_at

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

我希望有人可以帮助我!

2 个答案:

答案 0 :(得分:17)

修改您的用户模型并添加:

protected $primaryKey = 'customer_id';

答案 1 :(得分:3)

您可以设置messageA = the fields are {0} and {1} 模型中的$primaryKey字段以指定表格的主键:

User