get[NameOfAttribute]Attribute  模型获取器  set[NameOfAttribute]Attribute 模型修改器

$appends = [

'NameOfAttribute' 追加

];

public function getDisplayNameAttribute()
{
    return $this->nickname ? $this->nickname : $this->name;
}

    public function setCardNoAttribute($value)
{
    $value = str_replace(' ', '', $value);  // 将所有空格去掉
    $this->attributes['card_no'] = encrypt($value);
}

标签: none

添加新评论