Example 5-36. Decorating setting the value of an attribute using Eloquent mutators
// Defining the mutatorclassOrderextendsModel {publicfunctionsetAmountAttribute($value) {$this->attributes['amount'] = $value >0? $value :0; }}// Using the mutator$order->amount ='15'
这表明赋值器以$this->attributes以字段名设置数据
现在让我们给字段设置个代理,如示例5-37
Example 5-37. Allowing for setting the value of a nonexistent attribute using Eloquent mutators
// Defining the mutatorclassOrderextendsModel {publicfunctionsetWorkgroupNameAttribute($workgroupName) {$this->attributes['email'] ="{$workgroupName}@ourcompany.com"; }}// Using the mutator$order->workgroup_name ='jstott';