You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: README.md
+6-32
Original file line number
Diff line number
Diff line change
@@ -541,7 +541,7 @@ class UserResource extends JsonApiResource
541
541
}
542
542
```
543
543
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.
545
545
546
546
```php
547
547
<?php
@@ -573,7 +573,7 @@ class UserResource extends JsonApiResource
573
573
574
574
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.
575
575
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.
577
577
578
578
```php
579
579
<?php
@@ -604,6 +604,10 @@ class UserResource extends JsonApiResource
604
604
605
605
#### Customising the relationship resource class guessing
606
606
607
+
```php
608
+
609
+
```
610
+
607
611
//----- Everything that follows is WIP and should be ignored ------- //
608
612
609
613
## Resource Identification
@@ -620,36 +624,6 @@ You can customise how this works to support other types of objects and behaviour
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`.
// 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...
0 commit comments