【发布时间】:2020-06-30 02:18:22
【问题描述】:
我有一个结构如下的消息表:
- id sender_id receiver_id pet_id 描述
描述是文本消息。我通过获取发送者为用户或接收者为用户的所有消息,然后通过我想要的 petId 过滤它们来获取与特定宠物相关的用户消息。
function messagesByPet($petId,$userId){
$messages = Message::where('sender_id',$userId)->orWhere('receiver_id',$userId)->orderBy('created_at','asc')->get();
$message = $messages->where('pet_id', $petId);
return $message;
}
上述函数有效,但我收到的 JSON 如下。我不想要其中的索引,例如“0”“3”。如何删除它们?
{
"0": {
"id": 197,
"sender_id": "5718",
"receiver_id": "5716",
"pet_id": "5113",
"description": "Hi",
"created_at": "2020-03-16 05:29:41",
"updated_at": "2020-03-16 05:29:41"
},
"3": {
"id": 203,
"sender_id": "5718",
"receiver_id": "5716",
"pet_id": "5113",
"description": "Hi",
"created_at": "2020-03-18 22:06:40",
"updated_at": "2020-03-18 22:06:40"
}
}
【问题讨论】:
标签: php json laravel api eloquent