Reserved word on eloquent models

旧时模样 提交于 2019-12-23 13:57:29

问题


I have a Product model and a Attribute model.

Products have Attributes.

Problem is I cant use Attributes as a member of a Product class that extends eloquent as eloquent uses this already. Is there a way around this?

class Product extends Model 
{
    protected $attributes;

    // ...
}

回答1:


You won't get around renaming your relation. e.g. productAttributes.

The problem here is, that the attributes property is used a lot by Eloquent and there is no way to change that by configuration or overriding a small piece of code. You would need to override a lot of classes to change the name to something else, which is definitely not worth it.



来源:https://stackoverflow.com/questions/27485123/reserved-word-on-eloquent-models

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!