关于Lumen 8,我有:
Store
我可以在没有任何问题的情况下获得我的Store,并在下面得到json:
{
"id_store": 1,
"name": "Abcde",
"email": "",
"phone": "0123456789"
}我想了解一下Store的开放/关闭时间。在我的模型中,我有一个数组(用于测试),我可以这样显示它:
return response()->json(['item' => $store, 'time' => $store->getTime()], 200);得到这样的结果:
{
"item": {
"id_store": 1,
"name": "Abcde",
"email": "",
"phone": "0123456789"
},
"time": {
"1": "January",
"2": "February",
"3": "March"
}
}问题是我现在有两个部分。如何在我的存储值中包含这个数组?如下所示:
{
"id_store": 1,
"name": "Abcde",
"email": "",
"phone": "0123456789"
"time": {
"1": "January",
"2": "February",
"3": "March"
}
}发布于 2022-01-18 08:30:35
Missreaded,在Laravel中,您可以使用参考资料API参考资料,我想在Lumen中,更多的文档在这里:https://laravel.com/docs/8.x/eloquent-resources
在你的资源里,只要有这样的东西:
public function toArray($request)
{
return [
'id_store' => $this->id_store,
'name' => $this->name,
'email' => $this->email,
'phone' => $this->phone,
'time' => $this->->getTime(),
];
}或者只返回这样的东西:
$store->time = $store->getTime();
return response()->json($store, 404);为什么是404吨?
https://stackoverflow.com/questions/70752349
复制相似问题