Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

What is the cleanest way to prevent a model field from ever being updated?

Lets say that I don't want a UUID field to be updatable: Should I check for ->hasChanged('uuid') in the beforeUpdate event and cancel if it is changed? Is there a cleaner way to do it, perhaps in the initialize method?

edited Jan '15


Or the beforeUpdate() event in a model class.

public function beforeUpdate()
    // If password field is empty, ignore it
    if (empty($this->password)) {


Sure. I like it because I can add it to the initalize function, which I keep at the bottom of the model.


I should do $this->skipAttributesOnUpdate(["password"]); of Edward in a initialize function if you are sure you NEVER want to get updated.