prevent update a field

Submitted by Tefoh - 2 weeks 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;
    }
}