美文网首页
laravel 增加不存在数据库的字段

laravel 增加不存在数据库的字段

作者: 陌北v1 | 来源:发表于2018-01-17 11:04 被阅读0次

有时候您可能想要增加不存在数据库字段的属性数据。这时候只要定义一个获取器即可:

public function getIsAdminAttribute()
{
    return $this->attributes['admin'];
}

定义好获取器之后,再把对应的属性名称加到模型里的 appends 属性:

protected $appends = ['is_admin'];

相关文章

网友评论

      本文标题:laravel 增加不存在数据库的字段

      本文链接:https://www.haomeiwen.com/subject/oobyoxtx.html