开发框架 \ Laravel \ laravel setFooAttribute and getFooAttribute的使用

laravel setFooAttribute and getFooAttribute的使用

总点击52
简介:参考链接  https://laravel.com/docs/5.5/eloquent-mutators#array-and-json-casting setFooAttribute在设置(eg:insertupdate)的时候会将$obj->foo=\'value\'的时候,操作数据库之前自动转化一下

参考链接  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);

}


0人推荐

推荐文章

热门标签

意见反馈 常见问题 官方微信 返回顶部