我有一个返回用户数据库通知的函数(用户模型是Notifiable):
return $user->notifications()->get();
返回的结果是这样的:
[
{
"id": "5d6548d3-1f9b-4da5-b332-afbf428df775",
"type": "Meysam\\Notification\\Classes\\CommentCreated",
"notifiable_id": 1,
"notifiable_type": "RainLab\\User\\Models\\User",
"data": {
"userId": 2,
"commentId": 18
},
"read_at": null,
"created_at": "2018-03-05 09:58:34",
"updated_at": "2018-03-05 09:58:34"
},
{
"id": "2e22e24e-a972-4a30-afeb-0049a40966a7",
"type": "Meysam\\Notification\\Classes\\CommentCreated",
"notifiable_id": 1,
"notifiable_type": "RainLab\\User\\Models\\User",
"data": {
"userId": 3,
"commentId": 17
},
"read_at": null,
"created_at": "2018-03-05 09:38:38",
"updated_at": "2018-03-05 09:38:38"
}
]
在返回之前修改此集合的最佳方法是什么?例如,我想"id"
从对象中删除字段,将字段的值更改"type"
为,并为每个项目"CommentCreated"
添加新字段。将,和属性添加到模型类"url", "username", "email", etc
是一个好主意(如果是,如何)?API 资源在这里有用吗?hidden
visible
append
DatabaseNotification