#How to mapping data object in laravel?

7 messages · Page 1 of 1 (latest)

lunar lantern
#

Is there any way that I can use to mapping all this data? from the scope query of model. So I just want to hide the data of email & phone number in the comment user.
{
"id": 1,
"name": "Hello Tayos",
"address": "Hello World",
"description": "Hello World",
"status": 1,
"created_at": "2024-08-29T09:55:47.000000Z",
"updated_at": "2024-08-29T10:05:04.000000Z",
"user": {
"id": 1,
"role_id": 1,
"desa_id": null,
"email": "",
"status": 1,
"email_verified_at": "2024-08-29T08:50:22.000000Z",
"created_at": "2024-08-29T08:50:23.000000Z",
"updated_at": "2024-08-29T08:50:23.000000Z",
"profile": {
"id": 1,
"user_id": 1,
"name": "",
"birth_date": null,
"place_of_birth": null,
"address": null,
"phone": "",
"gender": "",
"photo": null,
"created_at": "2024-08-29T08:50:23.000000Z",
"updated_at": "2024-08-29T08:50:23.000000Z"
}
},
"comments": [
{
"id": 2,
"kejadian_id": 1,
"user_id": 1,
"comment": "Bagaimana",
"created_at": "2024-08-29T10:01:12.000000Z",
"updated_at": "2024-08-29T10:01:12.000000Z",
"user": {
"id": 1,
"role_id": 1,
"desa_id": null,
"email": "",
"status": 1,
"email_verified_at": "2024-08-29T08:50:22.000000Z",
"created_at": "2024-08-29T08:50:23.000000Z",
"updated_at": "2024-08-29T08:50:23.000000Z",
"profile": {
"id": 1,
"user_id": 1,
"name": "",
"birth_date": null,
"place_of_birth": null,
"address": null,
"phone": "",
"gender": "",
"photo": null,
"created_at": "2024-08-29T08:50:23.000000Z",
"updated_at": "2024-08-29T08:50:23.000000Z"
}
}
}
]
}

toxic zenith
lunar lantern
#

Is it possible to make it in scope?

toxic zenith
light wind
#

If phone and email should always be hidden when serialized to array or json, just add this to your profile model

protected $hidden = ['email', 'phone'];
lunar lantern