参考链接 https://laravel.com/docs/5.5/eloquent-mutators#array-and-json-casting
setFooAttribute 在设置(eg: insert update) 的时候 会将$obj->foo = 'value'的时候,操作数据库之前 自动转化一下
getFooAttribute 在获取foo属性的时候 $obj->foo 会转化
注意:
大驼峰格式
使用例子(自定义用户登录):
这样存进数据库的数据就是hash加密过的了
public function setPasswordAttribute($password)
{
$this->attributes['password'] = bcrypt($password);
}