嗨,我想合并两个数组。我有一张桌子positions和candidates。candidates表有一个外键pos_id。这就是我想要实现的格式。
[
{
"position": {
"name": "",
"type": "",
"max": "",
"candidate": [
{
"name": ""
},
{
"name": ""
}
]
}
},
{发布于 2018-11-03 22:29:05
在Position模型上使用candidate关系,您将能够通过使用以下内容来实现这一点:
Position::with('candidate')
->get()
->toArray();您的关系将如下所示:
// Position.php
public function candidate() {
return $this->hasOne('App\Candidate', 'pos_id');
}https://stackoverflow.com/questions/53131835
复制相似问题