Change default primary key in Eloquent

前端 未结 6 438
长发绾君心
长发绾君心 2020-12-05 01:58

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 m

6条回答
  •  眼角桃花
    2020-12-05 02:07

    The primary key variable is case sensitive and must be $primaryKey to work.

    Example:

    protected $primaryKey = 'your_primary_key_id';

    Example within a Model class:

    class User extends Eloquent {
    
        protected $primaryKey = 'your_primary_key_id';
    
    }
    

提交回复
热议问题