Skip to content

Commit 61be1d9

Browse files
committed
wip
1 parent d1eb1f7 commit 61be1d9

File tree

1 file changed

+6
-32
lines changed

1 file changed

+6
-32
lines changed

README.md

+6-32
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ class UserResource extends JsonApiResource
541541
}
542542
```
543543

544-
The above implementation would make a HTTP request to our microservice even when the client is excluding the `avatar` attribute via sparse fieldsets or minimal attributes. To improve performance when this attribute is not being returned we can wrap the value in a Closure. The Closure will only be evaluated when the `avatar` is to be returned.
544+
The above implementation would make a HTTP request to our microservice even when the client is excluding the `avatar` attribute via sparse fieldsets or minimal attributes. To improve performance when this attribute is not being returned we can wrap the value in a `Closure`. The `Closure` will only be evaluated when the `avatar` is to be returned.
545545

546546
```php
547547
<?php
@@ -573,7 +573,7 @@ class UserResource extends JsonApiResource
573573

574574
As we saw in the [adding relationships](#adding-relationships) section, the `$relationships` property is the fastest way to specify the available relationships for a resource. In some scenarios you may need greater control over the relationships you are making available. If that is the case, you may implement the `toRelationships()` method. This will grant you access to the current request and allow for conditional logic.
575575

576-
The value must always be wrapped in a Closure. The Closure will only be called if the relationships is requested by the client.
576+
The value must always be wrapped in a `Closure`, which will only be called if the relationships is requested by the client.
577577

578578
```php
579579
<?php
@@ -604,6 +604,10 @@ class UserResource extends JsonApiResource
604604

605605
#### Customising the relationship resource class guessing
606606

607+
```php
608+
609+
```
610+
607611
//----- Everything that follows is WIP and should be ignored ------- //
608612

609613
## Resource Identification
@@ -620,36 +624,6 @@ You can customise how this works to support other types of objects and behaviour
620624

621625
Nice. Well that was easy, so let's move onto...
622626

623-
624-
## Resource Relationships
625-
626-
`[JSON:API` docs: Relationships](https://jsonapi.org/format/#document-resource-object-relationships)
627-
628-
Just like we saw with attributes above, we can specify relationships that should be available on the resource by using the `toRelationships(Request $request)` method, however with relationships you should _always_ wrap the values in a `Closure`.
629-
630-
```php
631-
<?php
632-
633-
class UserResource extends JsonApiResource
634-
{
635-
public function toRelationships($request): array
636-
{
637-
return [
638-
'posts' => fn () => PostResource::collection($this->posts),
639-
'subscription' => fn () => SubscriptionResource::make($this->subscription),
640-
'profileImage' => fn () => optional($this->profileImage, fn (ProfileImage $profileImage) => ProfileImageResource::make($profileImage)),
641-
// if the relationship has been loaded and is null, can we not just return the resource still and have a nice default? That way you never have to handle any of this
642-
// optional noise?
643-
// also is there a usecase for returning a resource linkage right from here and not a full resource?
644-
];
645-
}
646-
}
647-
```
648-
649-
> Note: "links" and "meta" are not yet supported for relationships, but they are WIP. Resource linkage "meta" is not yet implemented. Let me know if you have a use-case you'd like to use it for!
650-
651-
Each `Closure` is only resolved when the relationship has been included by the client...
652-
653627
## Resource Links
654628

655629
`[JSON:API` docs: Links](https://jsonapi.org/format/#document-resource-object-links)

0 commit comments

Comments
 (0)