使用 Laravel 为 React-Native 应用程序提供 json 响应
有人告诉我,我们在前端有一些限制,我们不能使用正常的 Eloquent json 响应,相反,我应该准备如下响应:
[
{
"title": null,
"type": "animals",
"description": null,
"items": [
{
"type": "animal",
"content": {
"id": 31,
"image": null,
"name": "Asghar's dog",
"age": null,
"race": null,
"species_id": 1,
"reason": [
"Home"
]
}
}
]
},
{
"title": "Recommend",
"type": "recommendations",
"description": null,
"items": [
{
"type": "self_checks",
"content": {
"type": "prompt",
"title": "Self check for Asghar's dog.",
"description": "A short Self check.",
"cta_text": "Los geht’s"
}
},
{
"type": "worm_checks",
"content": {
"title": "Wurm-Vorsorge für Asghar's dog.",
"description": "Finde heraus, wie hoch das Wurm-Risiko deiner Fellnase ist.",
"cta_text": "Los geht’s",
"health_check_payload": {
"url": "https://****.de/check/worms?utm_term=Worms&utm_content=primer",
"title": "Wurm Check"
}
}
}
]
}
]
我需要知道应该如何构建我的代码以避免代码重复并保留它干净的。另外,我正在寻找有关此类回复的任何文件。
I've been told that we have some limitations in front end side and we can't use the normal Eloquent json responses, instead I should prepare responses like:
[
{
"title": null,
"type": "animals",
"description": null,
"items": [
{
"type": "animal",
"content": {
"id": 31,
"image": null,
"name": "Asghar's dog",
"age": null,
"race": null,
"species_id": 1,
"reason": [
"Home"
]
}
}
]
},
{
"title": "Recommend",
"type": "recommendations",
"description": null,
"items": [
{
"type": "self_checks",
"content": {
"type": "prompt",
"title": "Self check for Asghar's dog.",
"description": "A short Self check.",
"cta_text": "Los geht’s"
}
},
{
"type": "worm_checks",
"content": {
"title": "Wurm-Vorsorge für Asghar's dog.",
"description": "Finde heraus, wie hoch das Wurm-Risiko deiner Fellnase ist.",
"cta_text": "Los geht’s",
"health_check_payload": {
"url": "https://****.de/check/worms?utm_term=Worms&utm_content=primer",
"title": "Wurm Check"
}
}
}
]
}
]
I need to know how should I structure my code to avoid code repetition and keep it clean. Also, I'm looking for any document regarding this type of responses.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论