tpphu / golang-training

Golang for Backend Developer with Nordic Coder
https://nordiccoder.com/khoa-hoc/golang-for-backend-dev/
131 stars 50 forks source link

Giải đáp thắc mắc về transformation #17

Closed tpphu closed 5 years ago

tpphu commented 5 years ago

Ngữ cảnh

  1. Ngữ cảnh 1

When building an API, you may need a transformation layer that sits between your Eloquent models and the JSON responses that are actually returned to your application's users. Laravel's resource classes allow you to expressively and easily transform your models and model collections into JSON.
 giống như model user có field password khi em query trả về 1 model user, trong đó mặc định password

  1. Ngữ cảnh 2

model em muon field password đc hash thì sao thầy, ví dụ md5

tpphu commented 5 years ago

Với tình huông password mình không muốn gởi về cho client thì mình dùng tag: json:"-"

Với các tình huống khác, thì demo các lần sau sẽ đổi thành đối tượng user để cho các bạn được rõ.