@@ -57,32 +57,29 @@ public static function configure(?string $version = null, array $ext = [], array
5757 }
5858
5959 /**
60- * Set the string that should wrap the outer-most resource array .
60+ * Get the resource's ID .
6161 *
62- * @param string $value
63- * @return never
64- *
65- * @throws \RuntimeException
62+ * @param \Illuminate\Http\Request $request
63+ * @return string
6664 */
67- #[\Override]
68- public static function wrap ($ value )
65+ public function id (Request $ request )
6966 {
70- throw new BadMethodCallException ( sprintf ( ' Using %s() method is not allowed. ' , __METHOD__ ) );
67+ return $ this -> resolveResourceIdentifier ( $ request );
7168 }
7269
7370 /**
74- * Disable wrapping of the outer-most resource array .
71+ * Get the resource's type .
7572 *
76- * @return never
73+ * @param \Illuminate\Http\Request $request
74+ * @return string
7775 */
78- #[\Override]
79- public static function withoutWrapping ()
76+ public function type (Request $ request )
8077 {
81- throw new BadMethodCallException ( sprintf ( ' Using %s() method is not allowed. ' , __METHOD__ ) );
78+ return $ this -> resolveResourceType ( $ request );
8279 }
8380
8481 /**
85- * Resource "links" for JSON:API .
82+ * Get the resource's links .
8683 *
8784 * @param \Illuminate\Http\Request $request
8885 * @return array
@@ -93,7 +90,7 @@ public function links(Request $request)
9390 }
9491
9592 /**
96- * Resource "meta" for JSON:API .
93+ * Get the resource's meta information .
9794 *
9895 * @param \Illuminate\Http\Request $request
9996 * @return array
@@ -103,28 +100,6 @@ public function meta(Request $request)
103100 return $ this ->jsonApiMeta ;
104101 }
105102
106- /**
107- * Resource "id" for JSON:API.
108- *
109- * @param \Illuminate\Http\Request $request
110- * @return string
111- */
112- public function id (Request $ request )
113- {
114- return $ this ->resolveResourceIdentifier ($ request );
115- }
116-
117- /**
118- * Resource "type" for JSON:API.
119- *
120- * @param \Illuminate\Http\Request $request
121- * @return string
122- */
123- public function type (Request $ request )
124- {
125- return $ this ->resolveResourceType ($ request );
126- }
127-
128103 /**
129104 * Get any additional data that should be returned with the resource array.
130105 *
@@ -166,39 +141,44 @@ public function resolve($request = null)
166141 #[\Override]
167142 public function withResponse (Request $ request , JsonResponse $ response ): void
168143 {
169- $ response ->header ('Content-type ' , 'application/vnd.api+json ' );
144+ $ response ->header ('Content-Type ' , 'application/vnd.api+json ' );
170145 }
171146
172147 /**
173- * Transform JSON resource to JSON:API .
148+ * Create a new resource collection instance .
174149 *
175- * @param array $links
176- * @param array $meta
177- * @return $this
150+ * @param mixed $resource
151+ * @return \Illuminate\Http\Resources\JsonApi\AnonymousResourceCollection
178152 */
179- public function asJsonApi (array $ links = [], array $ meta = [])
153+ #[\Override]
154+ protected static function newCollection ($ resource )
180155 {
181- if (! empty ($ links )) {
182- $ this ->jsonApiLinks = array_merge ($ this ->jsonApiLinks , $ links );
183- }
184-
185- if (! empty ($ meta )) {
186- $ this ->jsonApiMeta = array_merge ($ this ->jsonApiMeta , $ meta );
187- }
156+ return new AnonymousResourceCollection ($ resource , static ::class);
157+ }
188158
189- return $ this ;
159+ /**
160+ * Set the string that should wrap the outer-most resource array.
161+ *
162+ * @param string $value
163+ * @return never
164+ *
165+ * @throws \RuntimeException
166+ */
167+ #[\Override]
168+ public static function wrap ($ value )
169+ {
170+ throw new BadMethodCallException (sprintf ('Using %s() method is not allowed. ' , __METHOD__ ));
190171 }
191172
192173 /**
193- * Create a new resource collection instance .
174+ * Disable wrapping of the outer-most resource array .
194175 *
195- * @param mixed $resource
196- * @return \Illuminate\Http\Resources\JsonApi\AnonymousResourceCollection
176+ * @return never
197177 */
198178 #[\Override]
199- protected static function newCollection ( $ resource )
179+ public static function withoutWrapping ( )
200180 {
201- return new AnonymousResourceCollection ( $ resource , static ::class );
181+ throw new BadMethodCallException ( sprintf ( ' Using %s() method is not allowed. ' , __METHOD__ ) );
202182 }
203183
204184 /**
0 commit comments