File tree 2 files changed +29
-4
lines changed
2 files changed +29
-4
lines changed Original file line number Diff line number Diff line change @@ -110,7 +110,7 @@ public function transformWith($transformer)
110
110
}
111
111
112
112
/**
113
- * Specify the includes
113
+ * Specify the includes.
114
114
*
115
115
* @param array|string $includes Array or csv string of resources to include
116
116
*
@@ -188,6 +188,21 @@ public function toArray()
188
188
* @throws \Spatie\Fractal\Exceptions\NoTransformerSpecified
189
189
*/
190
190
protected function transform ($ conversionMethod )
191
+ {
192
+ $ fractalData = $ this ->createData ();
193
+
194
+ return $ fractalData ->$ conversionMethod ();
195
+ }
196
+
197
+ /**
198
+ * Create fractal data.
199
+ *
200
+ * @return \League\Fractal\Scope
201
+ *
202
+ * @throws \Spatie\Fractal\Exceptions\InvalidTransformation
203
+ * @throws \Spatie\Fractal\Exceptions\NoTransformerSpecified
204
+ */
205
+ public function createData ()
191
206
{
192
207
if (is_null ($ this ->transformer )) {
193
208
throw new NoTransformerSpecified ();
@@ -203,9 +218,7 @@ protected function transform($conversionMethod)
203
218
204
219
$ resource = $ this ->getResource ();
205
220
206
- $ fractalData = $ this ->manager ->createData ($ resource );
207
-
208
- return $ fractalData ->$ conversionMethod ();
221
+ return $ this ->manager ->createData ($ resource );
209
222
}
210
223
211
224
/**
Original file line number Diff line number Diff line change @@ -97,4 +97,16 @@ public function it_can_create_a_resource()
97
97
98
98
$ this ->assertInstanceOf (\League \Fractal \Resource \ResourceInterface::class, $ resource );
99
99
}
100
+
101
+ /**
102
+ * @test
103
+ */
104
+ public function it_can_create_fractal_data ()
105
+ {
106
+ $ resource = $ this ->fractal
107
+ ->collection ($ this ->testBooks , new TestTransformer ())
108
+ ->createData ();
109
+
110
+ $ this ->assertInstanceOf (\League \Fractal \Scope::class, $ resource );
111
+ }
100
112
}
You can’t perform that action at this time.
0 commit comments