Attribute Casting

Is there any options for a convenient method of converting attributes to the common data type.

Yes.
You can use Moment.js which is used internally (by default) by AdonisJs.
You can check this post even if in your case you do not need to use Moment.js under that specific circumstance: Moment JS in Adonis Framework

How about the array/json field. I think Moment.js only for the date-time

{
  "id": 1,
  "username": "1@1.cv",
  "email": "1@1.cv",
  "roles": [
    {
      "id": 2,
      "name": "Singer",
      "permissions": "{\"userCreate\": false, \"userUpdate\": true, \"userView\": true, \"userDelete\": false}",
      "pivot": {
        "role_id": 2,
        "user_id": 1
      }
    }
  ]
}

I want to convert field permissions into JSON

I found the solution adonis-jsonable
maybe adonis should have some official package like this

1 Like