I have the following method:
public static function list()
{
return static::with(['links' => function($query) {
$query->select('link_id');
}])->get();
}
That returns the following output:
"objects": [
{
"id": 6,
"links": [
{
link_id: 6,
pivot: {
object_id: 6,
link_id: 6
}
},
{
link_id: 7,
pivot: {
object_id: 6,
link_id: 7
}
}
]
}
]
How can I make it return an array of ids for "links" using the "link_id" field value, as in:
"objects": [
{
"id": 6,
"links": [6, 7]
}
]
2
Answers
Try something like: