@@ -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,6 +106,12 @@ public function collection(Collection $collection, $transformer, $parameters = [
106106 $ parameters = [];
107107 }
108108
109+ if ($ transformer !== null ) {
110+ $ binding = $ this ->transformer ->register ($ class , $ transformer , $ parameters , $ after );
111+ } else {
112+ $ binding = $ this ->transformer ->getBinding ($ collection );
113+ }
114+
109115 $ binding = $ this ->transformer ->register ($ class , $ transformer , $ parameters , $ after );
110116
111117 return new Response ($ collection , 200 , [], $ binding );
@@ -130,7 +136,11 @@ public function item($item, $transformer, $parameters = [], Closure $after = nul
130136 $ parameters = [];
131137 }
132138
133- $ binding = $ this ->transformer ->register ($ class , $ transformer , $ parameters , $ after );
139+ if ($ transformer !== null ) {
140+ $ binding = $ this ->transformer ->register ($ class , $ transformer , $ parameters , $ after );
141+ } else {
142+ $ binding = $ this ->transformer ->getBinding ($ item );
143+ }
134144
135145 return new Response ($ item , 200 , [], $ binding );
136146 }
@@ -153,7 +163,11 @@ public function paginator(Paginator $paginator, $transformer, array $parameters
153163 $ class = get_class ($ paginator ->first ());
154164 }
155165
156- $ binding = $ this ->transformer ->register ($ class , $ transformer , $ parameters , $ after );
166+ if ($ transformer !== null ) {
167+ $ binding = $ this ->transformer ->register ($ class , $ transformer , $ parameters , $ after );
168+ } else {
169+ $ binding = $ this ->transformer ->getBinding ($ paginator ->first ());
170+ }
157171
158172 return new Response ($ paginator , 200 , [], $ binding );
159173 }
0 commit comments