@@ -93,7 +93,7 @@ public function noContent()
93
93
*
94
94
* @return \Dingo\Api\Http\Response
95
95
*/
96
- public function collection (Collection $ collection , $ transformer , $ parameters = [], Closure $ after = null )
96
+ public function collection (Collection $ collection , $ transformer = null , $ parameters = [], Closure $ after = null )
97
97
{
98
98
if ($ collection ->isEmpty ()) {
99
99
$ class = get_class ($ collection );
@@ -106,7 +106,11 @@ public function collection(Collection $collection, $transformer, $parameters = [
106
106
$ parameters = [];
107
107
}
108
108
109
- $ binding = $ this ->transformer ->register ($ class , $ transformer , $ parameters , $ after );
109
+ if ($ transformer !== null ) {
110
+ $ binding = $ this ->transformer ->register ($ class , $ transformer , $ parameters , $ after );
111
+ } else {
112
+ $ binding = $ this ->transformer ->getBinding ($ collection );
113
+ }
110
114
111
115
return new Response ($ collection , 200 , [], $ binding );
112
116
}
@@ -135,7 +139,11 @@ public function item($item, $transformer, $parameters = [], Closure $after = nul
135
139
$ parameters = [];
136
140
}
137
141
138
- $ binding = $ this ->transformer ->register ($ class , $ transformer , $ parameters , $ after );
142
+ if ($ transformer !== null ) {
143
+ $ binding = $ this ->transformer ->register ($ class , $ transformer , $ parameters , $ after );
144
+ } else {
145
+ $ binding = $ this ->transformer ->getBinding ($ item );
146
+ }
139
147
140
148
return new Response ($ item , 200 , [], $ binding );
141
149
}
@@ -158,7 +166,11 @@ public function paginator(Paginator $paginator, $transformer, array $parameters
158
166
$ class = get_class ($ paginator ->first ());
159
167
}
160
168
161
- $ binding = $ this ->transformer ->register ($ class , $ transformer , $ parameters , $ after );
169
+ if ($ transformer !== null ) {
170
+ $ binding = $ this ->transformer ->register ($ class , $ transformer , $ parameters , $ after );
171
+ } else {
172
+ $ binding = $ this ->transformer ->getBinding ($ paginator ->first ());
173
+ }
162
174
163
175
return new Response ($ paginator , 200 , [], $ binding );
164
176
}
0 commit comments