我有三个桌子,
users
id name
1 personA
2 personB
3 personC
skills
id name
1 html
2 css
3 javascript
userskills
userid skills_id
2 3,1
1 2,3
我为上述表格创建了三个模型。
我的结果代码是
$user = User::with('skills')->first();
return response()->json($user->get());
这样我的结果就像
"success": {
"id": 2,
"name": "personB",
"skills": [
{
"user_id": 2,
"skills_id": "3,1",
}
]
}
但是我希望最后得到我的结果,
"success": {
"id": 2,
"name": "personB",
"skills": [
{
"user_id": 2,
"skills_id": "3,1",
"skills": "javascript"
}
{
"user_id": 2,
"skills_id": "3,1",
"skills": "html"
}
]
}
我尝试了许多方法,但找不到。我怎样才能得到上面的结果?