In my application, there are two models:
- person
- subject
there's a many-to-many relationship between those two.
In order to fetch all people (person) with their respective subjects, I do;
$people = Person::with(['subjects' => function($query) {
$query->select('id');
}]);
Results in:
{
...
"subjects": [
{
"id": 16
},
{
"id": 21
},
{
"id": 32
}
],
},
I am wondering is there an elegant way to get an array of subject ids instead:
{
...
"subjects": [
10,
14,
21,
38
],
},