【问题标题】:Laravel 5.2 auth change 'id' to 'customer_id'Laravel 5.2 auth 将 'id' 更改为 'customer_id'
【发布时间】:2016-04-12 22:48:23
【问题描述】:

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

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

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

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

我改变的地方:

配置/身份验证

'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

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

应用/用户

protected $table = 'klanten';

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

希望有人能帮帮我!

【问题讨论】:

    标签: laravel authentication laravel-5 laravel-5.2


    【解决方案1】:

    编辑您的用户模型并添加:

    protected $primaryKey = 'customer_id';
    

    【讨论】:

      【解决方案2】:

      您可以设置User模型中的$primaryKey字段来指定表的主键:

      protected $primaryKey = 'customer_id';
      

      【讨论】:

        猜你喜欢
        • 2016-04-12
        • 2023-03-05
        • 2016-04-02
        • 1970-01-01
        • 2017-01-17
        • 1970-01-01
        • 2016-09-07
        • 2016-05-07
        • 2018-01-07
        相关资源
        最近更新 更多