我正在与Eloquent和Laravel 5合作,在模型的$appends
属性上添加了一个字段,并使用mutator来获取它的值。我的问题是,只有当它被调用时才能获得这个字段?
public static $model = 'Model';
protected $table = 'table';
protected $primaryKey = 'idtable';
public $incrementing = false;
public $timestamps = false;
protected $appends = ['DescComposta'];
//Mutators
public function getDescCompostaAttribute()
{
return $this->attributes['desc_composta'] = 'yes';
}
谢谢大家!