我有以下方法:
public static function list()
{
return static::with(['links' => function($query) {
$query->select('link_id');
}])->get();
}
它返回以下输出:
"objects": [
{
"id": 6,
"links": [
{
link_id: 6,
pivot: {
object_id: 6,
link_id: 6
}
},
{
link_id: 7,
pivot: {
object_id: 6,
link_id: 7
}
}
]
}
]
如何使用“link_id”字段值使其返回“links”的id数组,如:
"objects": [
{
"id": 6,
"links": [6, 7]
}
]
2条答案
按热度按时间a1o7rhls1#
cbeh67ev2#
尝试以下操作: