我使用数据透视表使用多对多的关系。但问题是当我返回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",
}
]
}
我已经尝试过stackoverflow问题的各种解决方案,但它们似乎都没有用。我是Laravel的新手。如果你们需要关于模型的更多信息,我可以发布它。请帮忙。
答案 0 :(得分:1)
转到您的技能模型并设置:
protected $visible = ['id', 'value'];