这就是我现在正在做的:
protected $defaults = array(
'quantity' => 9,
);
public function __construct(array $attributes = array())
{
$this->setRawAttributes($this->defaults, true);
parent::__construct($attributes);
}
我将其建议为PR,因此我们无需在每个Model上都声明此构造函数,并且只需$defaults
在模型中声明数组即可轻松应用…
:
正如cmfolio指出的那样, :
只需覆盖$attributes
属性!像这样:
protected $attributes = array(
'quantity' => 9,
);
这里讨论了这个问题。