55use Ark4ne \JsonApi \Resources \Relationship ;
66use Ark4ne \JsonApi \Support \Includes ;
77use Illuminate \Http \Request ;
8+ use Illuminate \Support \Collection ;
89
910trait Relationships
1011{
@@ -13,7 +14,7 @@ trait Relationships
1314 *
1415 * @param \Illuminate\Http\Request $request
1516 *
16- * @return array<string, Relationship>
17+ * @return array<string, Relationship>|iterable<Relationship>
1718 *
1819 * ```
1920 * return [
@@ -30,6 +31,11 @@ protected function toRelationships(Request $request): iterable
3031 return [];
3132 }
3233
34+ /**
35+ * @param \Illuminate\Http\Request $request
36+ *
37+ * @return array<string, array{data?: mixed, links?: mixed, meta?: mixed}>
38+ */
3339 private function requestedRelationships (Request $ request ): array
3440 {
3541 $ relations = [];
@@ -49,6 +55,13 @@ private function requestedRelationships(Request $request): array
4955 return $ relations ;
5056 }
5157
58+ /**
59+ * @param bool $included
60+ * @param \Illuminate\Http\Request $request
61+ * @param \Ark4ne\JsonApi\Resources\Relationship $relationship
62+ *
63+ * @return array{data?: mixed, links?: mixed, meta?: mixed}
64+ */
5265 private function mapRelationship (
5366 bool $ included ,
5467 Request $ request ,
@@ -67,11 +80,11 @@ private function mapRelationship(
6780 foreach ($ resource ['with ' ] as $ key => $ value ) {
6881 $ this ->with [$ key ] = array_merge (
6982 $ this ->with [$ key ] ?? [],
70- collect ( $ value )->all ()
83+ ( new Collection ( $ value) )->all ()
7184 );
7285 }
7386 }
7487
75- return $ resource ['data ' ] ?? [] ;
88+ return $ resource ['data ' ];
7689 }
7790}
0 commit comments