我有一个模型,其中包含一些$fillable、可批量分配的字段。
但是,有些字段只能在创建时批量分配,而不能在更新时批量分配。
执行此操作的正确方法是什么?
谢谢。
发布于 2016-01-15 23:13:27
您可能会尝试覆盖模型上的getFillable。
public function getFillable()
{
if ($this->exists) {
// modify the fillable or return a different fillable array
}
return $this->fillable;
}发布于 2016-01-15 23:23:40
如果不想重载getFillable()
class MyModel extends Eloquent
{
public function create(array $attributes = []) {
$this->fill($attributes);
$this->protected_attriute = $attribute['protected_attribute'];
return $this;
}
}https://stackoverflow.com/questions/34813770
复制相似问题