我刚开始使用Api 平台并立即遇到如何过滤数据的问题。我有实体User
,我想过滤响应中存在的数据(JSON API 格式)
{
"links": {
"self": "/api/users"
},
"meta": {
"totalItems": 2,
"itemsPerPage": 30,
"currentPage": 1
},
"data": [
{
"id": "/api/users/1",
"type": "User",
"attributes": {
"_id": 1,
"username": "jonhdoe",
"isActive": true,
"address": null
}
},
{
"id": "/api/users/3",
"type": "User",
"attributes": {
"_id": 3,
"username": "test",
"isActive": true,
"address": null
}
}
]
}
所以我想删除例如3,但不使用通过请求发送的过滤器User
。id
我只想设置过滤器,当有人去/api/users
. 我期待api-platform 扩展,但这将应用于每个请求,例如/api/trucks
. 所以最后我只想得到类似的东西
{
"links": {
"self": "/api/users"
},
"meta": {
"totalItems": 1,
"itemsPerPage": 30,
"currentPage": 1
},
"data": [
{
"id": "/api/users/1",
"type": "User",
"attributes": {
"_id": 1,
"username": "jonhdoe",
"isActive": true,
"address": null
}
}
]
}