Change default primary key in Eloquent

Yes

class User extends Eloquent {

    protected $primaryKey = 'admin_id';

}

class User extends Eloquent {

    protected $primarykey = 'admin_id';

}

but

class User extends Eloquent {

    protected $primaryKey = 'admin_id';

}

note the letter K (capital) on the variable $primaryKey


If you are wanting to use a composite key (a string)

You need to make sure you set public $incrementing = false otherwise laravel will cast the field to an Integer, giving 0

class User extends Model {

    protected $primaryKey = 'my_string_key';
    public $incrementing = false;

}