@@ -48,7 +48,7 @@ protected function transformRecord($record, array $fields = [], array $include =
48
48
}
49
49
50
50
$ data = array_filter ([
51
- 'type ' => $ record ->getTable (),
51
+ 'type ' => str_slug ( $ record ->getTable () ),
52
52
'id ' => $ record ->id ,
53
53
'attributes ' => array_except ($ attributes , ['id ' ]),
54
54
'relationships ' => $ relationships ,
@@ -71,7 +71,7 @@ protected function transformRecordSimple($record)
71
71
72
72
return [
73
73
'data ' => [
74
- 'type ' => $ record ->getTable (),
74
+ 'type ' => str_slug ( $ record ->getTable () ),
75
75
'id ' => $ record ->id ,
76
76
'attributes ' => $ attributes ,
77
77
]
@@ -89,7 +89,7 @@ protected function transformRecordIdentifier($record)
89
89
{
90
90
return [
91
91
'data ' => [
92
- 'type ' => $ record ->getTable (),
92
+ 'type ' => str_slug ( $ record ->getTable () ),
93
93
'id ' => $ record ->id ,
94
94
]
95
95
];
@@ -100,16 +100,25 @@ protected function transformRecordIdentifier($record)
100
100
*
101
101
* @param Collection|LengthAwarePaginator $records
102
102
* @param array $fields
103
+ * @param array|null $include
103
104
*
104
105
* @return array
105
106
*/
106
- protected function transformCollection ($ records , array $ fields = [])
107
+ protected function transformCollection ($ records , array $ fields = [], array $ include = [] )
107
108
{
108
- $ data = $ records ->map (function ($ record ) use ($ fields ) {
109
- return $ this ->transformRecord ($ record , $ fields )['data ' ];
110
- })->toArray ();
111
-
109
+ $ data = [];
112
110
$ links = [];
111
+ $ included = [];
112
+
113
+ foreach ($ records as $ record ) {
114
+ $ object = $ this ->transformRecord ($ record , $ fields , $ include );
115
+
116
+ if (isset ($ object ['included ' ])) {
117
+ $ included = array_merge ($ included , $ object ['included ' ]);
118
+ }
119
+
120
+ $ data [] = $ object ['data ' ];
121
+ }
113
122
114
123
if ($ records instanceof LengthAwarePaginator) {
115
124
$ links ['first ' ] = $ records ->url (1 );
@@ -118,7 +127,7 @@ protected function transformCollection($records, array $fields = [])
118
127
$ links ['next ' ] = $ records ->nextPageUrl ();
119
128
}
120
129
121
- return array_merge (compact ('data ' ), array_filter (compact ('links ' )));
130
+ return array_merge (compact ('data ' ), array_filter (compact ('links ' , ' included ' )));
122
131
}
123
132
124
133
/**
0 commit comments