Change default primary key in Eloquent

Vuk Stanković picture Vuk Stanković · Nov 17, 2013 · Viewed 91.5k times · Source

Can I change Eloquent model primary key.

I want to set primary key for example admin_id instead of 'id'?

I know I can change table name for model like

protected $table = "admin";

Is there something similar for primary key?

Answer

phirschybar picture phirschybar · Nov 17, 2013

Yes

class User extends Eloquent {

    protected $primaryKey = 'admin_id';

}