问题
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