从 Laravel 5.2 中的 JSON 响应中删除 pivote 属性

Remove pivote attribute from JSON response in Laravel 5.2

我正在使用枢轴 table 使用多对多关系。但问题是当我返回 json 响应时,json 还包含 pivot 属性,如下所示:

{
        "id": 2,
        "job_title": "et",
        "job_description": "Iusto provident.",
        "job_industry": "Braun, Jast and Quigley",
        "job_location": "Christiansenland",
        "job_experience": 7,
        "employment_type": "full",
        "recruiter_id": 9,
        "status": 1,
        "posted_date": "2016-02-02 07:55:28",
        "skills": [
          {
            "id": 1,
            "value": "molestiae",
            "pivot": {
              "job_id": 2,
              "skill_id": 1
            }
          }
        ]
      }

我想要的是这样的:

{
        "id": 2,
        "job_title": "et",
        "job_description": "Iusto provident.",
        "job_industry": "Braun, Jast and Quigley",
        "job_location": "Christiansenland",
        "job_experience": 7,
        "employment_type": "full",
        "recruiter_id": 9,
        "status": 1,
        "posted_date": "2016-02-02 07:55:28",
        "skills": [
          {
            "id": 1,
            "value": "molestiae",
          }
        ]
      }

我尝试了 Whosebug 问题的各种解决方案,但其中 none 似乎有效。我是 Laravel 的新手。如果你们需要更多关于该模型的信息,我可以 post。请帮忙。

转到您的技能模型并设置:

protected $visible = ['id', 'value'];