@@ -93,7 +93,7 @@ public function noContent()
9393 *
9494 * @return \Dingo\Api\Http\Response
9595 */
96- public function collection (Collection $ collection , $ transformer , $ parameters = [], Closure $ after = null )
96+ public function collection (Collection $ collection , $ transformer = null , $ parameters = [], Closure $ after = null )
9797 {
9898 if ($ collection ->isEmpty ()) {
9999 $ class = get_class ($ collection );
@@ -106,7 +106,11 @@ public function collection(Collection $collection, $transformer, $parameters = [
106106 $ parameters = [];
107107 }
108108
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+ }
110114
111115 return new Response ($ collection , 200 , [], $ binding );
112116 }
@@ -135,7 +139,11 @@ public function item($item, $transformer, $parameters = [], Closure $after = nul
135139 $ parameters = [];
136140 }
137141
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+ }
139147
140148 return new Response ($ item , 200 , [], $ binding );
141149 }
@@ -158,7 +166,11 @@ public function paginator(Paginator $paginator, $transformer, array $parameters
158166 $ class = get_class ($ paginator ->first ());
159167 }
160168
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+ }
162174
163175 return new Response ($ paginator , 200 , [], $ binding );
164176 }
0 commit comments