@@ -13,15 +13,15 @@ trait Relationships
1313 *
1414 * @param \Illuminate\Http\Request $request
1515 *
16- * @return array<string, <Closure():< Relationship> | Relationship> >
16+ * @return array<string, Relationship>
1717 *
1818 * ```
1919 * return [
20- * 'avatar' => AvatarResource::make( $this->avatar),
21- * // with lazy evaluation
22- * 'posts' => fn () => PostResource::collection( $this->posts),
20+ * 'avatar' => AvatarResource::relationship(fn() => $this->avatar),
21+ * // as collection
22+ * 'posts' => PostResource::relationship(fn () => $this->posts)->asCollection( ),
2323 * // with laravel conditional relationships
24- * 'comments' => $this->when($this->canComments(), fn() => fn() => CommentResource::collection( $this->comments),
24+ * 'comments' => CommentResource::relationship(fn() => $this->when($this->canComments(), fn() => $this->comments))->asCollection( ),
2525 * ];
2626 * ```
2727 */
@@ -33,19 +33,14 @@ protected function toRelationships(Request $request): iterable
3333 private function requestedRelationships (Request $ request ): array
3434 {
3535 $ relations = [];
36- $ relationships = $ this ->toRelationships ($ request );
3736
38- foreach ($ this ->filter ( $ relationships ) as $ name => $ relationship ) {
39- $ relationship = value ( $ relationship );
37+ foreach ($ this ->toRelationships ( $ request ) as $ name => $ relationship ) {
38+ $ relationship-> forRelation ( $ name );
4039
41- if (!($ relationship instanceof Relationship)) {
42- $ relationship = new Relationship ($ relationship );
43- }
44-
45- $ minimal = !Includes::include ($ request , $ name );
40+ $ included = Includes::include ($ request , $ name );
4641
4742 $ relations [$ name ] = Includes::through ($ name , fn () => $ this ->mapRelationship (
48- $ minimal ,
43+ $ included ,
4944 $ request ,
5045 $ relationship
5146 ));
@@ -55,11 +50,11 @@ private function requestedRelationships(Request $request): array
5550 }
5651
5752 private function mapRelationship (
58- bool $ minimal ,
53+ bool $ included ,
5954 Request $ request ,
6055 Relationship $ relationship
6156 ): array {
62- $ resource = $ relationship ->toArray ($ request , $ minimal );
57+ $ resource = $ relationship ->toArray ($ request , $ included );
6358
6459 if (isset ($ resource ['included ' ])) {
6560 $ this ->with ['included ' ] = array_merge (
0 commit comments