Hide password field from JSON response


#1

How to hide password field from JSON response?

Laravel has a protected method named hidden who can mask field from JSON response.

protected $hidden = ['password'];

https://laravel.com/docs/5.5/eloquent-serialization#hiding-attributes-from-json

Adonis can be this?


#2

Hey @pirmax! :wave:

You need to define a getter for that.

class User extends Model {
  static get hidden () {
    return ['password']
  }
}

This will remove password attribute when calling instance.toJSON().