I have a model containing some $fillable, mass-assignable fields.
However, some of the fields should only be mass-assignable when creating, not when updating.
What is the correct method of doing this?
Thanks.
I have a model containing some $fillable, mass-assignable fields.
However, some of the fields should only be mass-assignable when creating, not when updating.
What is the correct method of doing this?
Thanks.
Potentially you could try overriding getFillable
on the model.
public function getFillable()
{
if ($this->exists) {
// modify the fillable or return a different fillable array
}
return $this->fillable;
}
If you don't want to overload getFillable()
class MyModel extends Eloquent
{
public function create(array $attributes = []) {
$this->fill($attributes);
$this->protected_attriute = $attribute['protected_attribute'];
return $this;
}
}