@@ -384,20 +384,35 @@ By default all resource objects will be encoded with their `self` link, e.g.:
384384}
385385```
386386
387- You can change this behaviour by overloading the ` getResourceLinks ` or ` getIncludedResourceLinks ` methods.
388- For example :
387+ You can change this behaviour by implementing the ` getResourceLinks ` method. For example, if you do not want any links
388+ to be serialized :
389389
390390``` php
391391class Schema extends SchemaProvider
392392{
393393 // ...
394394
395- public function getResourceLinks($resource)
395+ public function getResourceLinks($resource): ?array
396396 {
397- $links = parent::getResourceLinks($resource);
398- $links['foo'] = $this->createLink('posts/foo');
397+ return null;
398+ }
399+ }
400+ ```
401+
402+ If you return an array without any ` self ` key in it, the ` self ` link will be automatically added. If you do not want
403+ the ` self ` link to be set, set the array key ` self ` to ` false ` .
404+
405+ ``` php
406+ class Schema extends SchemaProvider
407+ {
408+ // ...
399409
400- return $links;
410+ public function getResourceLinks($resource): array
411+ {
412+ return [
413+ // "self" will automatically be added as it is not set to false.
414+ 'foo' => $this->createLink('posts/foo'),
415+ ];
401416 }
402417
403418}
@@ -423,33 +438,23 @@ This would result in the following resource object:
423438> The ` createLink ` method allows you to pass in link meta and set whether the URI is relative to the API or an
424439 absolute path.
425440
426- If you want to only change the links when the resource is appearing in the ` included ` section of the JSON API
427- document, overload the ` getIncludedResourceLinks() ` method instead.
428-
429441## Meta
430442
431- You can add top-level ` meta ` to your resource object using the ` getPrimaryMeta() ` or ` getInclusionMeta() ` methods
432- on your schema. These are called depending on whether your resource is appearing in either the primary ` data `
433- member of the JSON API document or the ` included ` member.
443+ You can add top-level ` meta ` to your resource object using the ` getResourceMeta() ` method
444+ on your schema.
434445
435- For example, the following would add meta to your resource object regardless of whether it is primary data or
436- included in the document:
446+ For example:
437447
438448``` php
439449class Schema extends SchemaProvider
440450{
441451 // ...
442452
443- public function getPrimaryMeta ($resource)
453+ public function getResourceMeta ($resource)
444454 {
445455 return ['foo' => 'bar'];
446456 }
447457
448- public function getInclusionMeta($resource)
449- {
450- return $this->getPrimaryMeta($resource);
451- }
452-
453458}
454459```
455460
0 commit comments