[英]How to force eloquent to accept 'ID' instead of 'id' when saving or updating a record in database?
in laravel, eloquent assumes primary key to be 'id', however, I'm forced to use an already existing database that has 'ID' as a primary key, as a result, the functions save() and update() are not updating the database records. 在laravel中,eloquent假设主键是'id',但是,我被迫使用已经存在的'ID'作为主键的数据库,因此,函数save()和update()不是更新数据库记录。 The question is how do I force eloquent to use 'ID'as the primary key?
问题是如何强制雄辩地使用'ID'作为主键?
I've already tried : 我已经尝试过了:
protected $primarykey = 'ID';
but still with no luck. 但仍然没有运气。 However when i change the database column name to 'id' the save() and update() functions works just fine, but this is not a solution that I can use in my case as the database is controlled by the company I'm working for.
但是当我将数据库列名更改为'id'时,save()和update()函数运行正常,但这不是我可以在我的情况下使用的解决方案,因为数据库是由我正在工作的公司控制的对于。
Variable names are case sensitive and the $primaryKey
property has a capital K
. 变量名称区分大小写,
$primaryKey
属性具有大写$primaryKey
K
Try changing this in your model. 尝试在模型中更改此项。
protected $primaryKey = 'ID';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.