Laravel 5.2 auth change 'id' to 'custo

2019-04-25 02:59发布

In this topic I asked a question: 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.

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

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

Things I've changed:

config/auth

'providers' => [
    'users' => [
        'driver' => 'eloquent',
        'model' => App\User::class,
        'table' => '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();
    });
}

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

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!

2条回答
\"骚年 ilove
2楼-- · 2019-04-25 03:23

edit your user model and add this:

protected $primaryKey = 'customer_id';
查看更多
我只想做你的唯一
3楼-- · 2019-04-25 03:23

you can set the $primaryKey filed in the User model to specify the primary key of your table:

protected $primaryKey = 'customer_id';
查看更多
登录 后发表回答