laravel 模型追加字段并赋值
//追加字段 protected $appends = ['state']; //赋值 public function getStateAttribute() { $status = $this->attributes['status']; if ($status == 1) { return '已授权'; } elseif ($status == 2) { return '取消授权'; } else { return '未知'; } }
//追加字段 protected $appends = ['state']; //赋值 public function getStateAttribute() { $status = $this->attributes['status']; if ($status == 1) { return '已授权'; } elseif ($status == 2) { return '取消授权'; } else { return '未知'; } }