分享 / 3 / 2 / 创建于 3年前 / 更新于 3年前
问题:我有状态字段status我想要把int类型的值1,2,3对应转换为:1待审核,2审核通过,3审核驳回。
说明:laravel 的model提供了getStatusAttribute方法,但是我想保留status字段,下面是我目前处理方法,各位大佬如果有更好的处理办法请务必朵蜜我~
$this->appends['status_name'] = 'statusName';
##三. 结果
如果是api服务,在模型增加
php protected $appends = ['status_name'];
增加getStatusNameAttribute如果传统的web应用。直接增加getStatusNameAttribute然后
getStatusNameAttribute
$mode->status_name
如果存在状态的模型较多,还可以增加Casts来自定义处理!
或者
使用 View Presenter 模式管理自定义属性
我要举报该,理由是:
如果是api服务,在模型增加
增加
getStatusNameAttribute
如果传统的web应用。直接增加
getStatusNameAttribute
然后
如果存在状态的模型较多,还可以增加Casts来自定义处理!
或者
使用 View Presenter 模式管理自定义属性