Slide 98
Slide 98 text
class Schema extends SchemaProvider
{
protected $resourceType = 'articles';
public function getId($resource)
{
return (string) $resource->getRouteKey();
}
public function getAttributes($resource)
{
return [
'title' => $resource->title,
'body' => $resource->body,
];
}
public function getRelationships($resource, $isPrimary, array $includedRelationships)
{
return [
'author' => [
self::SHOW_SELF => true,
self::SHOW_RELATED => true,
self::SHOW_DATA => isset($includedRelationships['author']),
self::DATA => function () use ($resource) {
return $resource->author;
},
Getting to JSON:API - Matt Stauffer