prevent update a field

Submitted by Tefoh - 4 years ago

maybe this is a nice way to prevent an eloquent model field being updated with mutators like this:

class User extends Model
{
    /**
     * prevent update first_name but it can create 
     *
     * @param  string  $value
     * @return void
     */
    public function setFirstNameAttribute($value)
    {
        if($this->first_name) {
            return;
        }
        
        $this->attributes['first_name'] = $value;
    }
}