@@ -125,12 +125,12 @@ public static function makeFromJson(JsonResponse $json)
125
125
*/
126
126
public function morph ($ format = 'json ' )
127
127
{
128
- $ this -> content = $ this ->getOriginalContent () ?? '' ;
128
+ $ content = $ this ->getOriginalContent () ?? '' ;
129
129
130
130
$ this ->fireMorphingEvent ();
131
131
132
- if (isset (static ::$ transformer ) && static ::$ transformer ->transformableResponse ($ this -> content )) {
133
- $ this -> content = static ::$ transformer ->transform ($ this -> content );
132
+ if (isset (static ::$ transformer ) && static ::$ transformer ->transformableResponse ($ content )) {
133
+ $ content = static ::$ transformer ->transform ($ content );
134
134
}
135
135
136
136
$ formatter = static ::getFormatter ($ format );
@@ -147,20 +147,22 @@ public function morph($format = 'json')
147
147
148
148
$ this ->fireMorphedEvent ();
149
149
150
- if ($ this -> content instanceof EloquentModel) {
151
- $ this -> content = $ formatter ->formatEloquentModel ($ this -> content );
152
- } elseif ($ this -> content instanceof EloquentCollection) {
153
- $ this -> content = $ formatter ->formatEloquentCollection ($ this -> content );
154
- } elseif (is_array ($ this -> content ) || $ this -> content instanceof ArrayObject || $ this -> content instanceof Arrayable) {
155
- $ this -> content = $ formatter ->formatArray ($ this -> content );
156
- } elseif ($ this -> content instanceof stdClass) {
157
- $ this -> content = $ formatter ->formatArray ((array ) $ this -> content );
150
+ if ($ content instanceof EloquentModel) {
151
+ $ content = $ formatter ->formatEloquentModel ($ content );
152
+ } elseif ($ content instanceof EloquentCollection) {
153
+ $ content = $ formatter ->formatEloquentCollection ($ content );
154
+ } elseif (is_array ($ content ) || $ content instanceof ArrayObject || $ content instanceof Arrayable) {
155
+ $ content = $ formatter ->formatArray ($ content );
156
+ } elseif ($ content instanceof stdClass) {
157
+ $ content = $ formatter ->formatArray ((array ) $ content );
158
158
} else {
159
159
if (! empty ($ defaultContentType )) {
160
160
$ this ->headers ->set ('Content-Type ' , $ defaultContentType );
161
161
}
162
162
}
163
163
164
+ $ this ->content = $ content ;
165
+
164
166
return $ this ;
165
167
}
166
168
0 commit comments