Laravel将发送的数据发送到请求中

时间:2017-04-11 18:01:24

标签: php laravel laravel-5

我正在使用Laravel 5.4实现API。我想将标题,描述,时间和user_id作为JSON发送,之后使用输入数据获取JSON响应。

这是我的代码:

{
"time": "201601301330CET",
"title": "Test meeting 2",
"description": "Test",
"user_id": 2
}

运行服务器后,我使用POSTMAN(body-> raw:)

发出帖子请求
{
"msg": "Meeting created",
"meeting": {
  "title": null,
  "description": null,
  "time": null,
  "user_id": null,
  "view_meeting": {
    "href": "api/v1/meeting/1",
    "method": "GET1"
  }
}
}

但它返回了这个:

{{1}}

为什么title,description,time和user_id字段为空?

1 个答案:

答案 0 :(得分:2)

您需要将邮差的content-type下拉列表设为JSON (application/json)。更改该设置会将响应中的null值更改为:

{
  "msg": "Meeting created",
  "meeting": {
    "title": "Test meeting 2",
    "description": "Test",
    "time": "201601301330CET",
    "user_id": 2,
    "view_meeting": {
      "href": "api/v1/meeting/1",
      "method": "GET1"
    }
  }
}