Add relations and for LexicalEntry to JSON API

This commit is contained in:
Leonard Smith 2020-10-07 11:08:09 -05:00
parent c6d43527e7
commit e41971a69c
3 changed files with 14 additions and 1 deletions

View File

@ -51,6 +51,10 @@ class Schema extends SchemaProvider
'words' => [
self::SHOW_SELF => true,
self::SHOW_RELATED => true,
self::SHOW_DATA => isset($includeRelationships['words']),
self::DATA => function () use ($resource) {
return $resource->words;
},
]
];
}

View File

@ -57,6 +57,6 @@ class Adapter extends AbstractAdapter
*/
protected function lexicalEntry()
{
return $this->hasOne();
return $this->belongsTo();
}
}

View File

@ -22,6 +22,11 @@ class Schema extends SchemaProvider
return (string) $resource->getRouteKey();
}
public function getIncludePaths()
{
return ['lexical-entry'];
}
/**
* @param \App\Word $resource
* the domain record being serialized.
@ -53,6 +58,10 @@ class Schema extends SchemaProvider
'lexical-entry' => [
self::SHOW_SELF => true,
self::SHOW_RELATED => true,
self::SHOW_DATA => isset($includeRelationships['lexical-entry']),
self::DATA => function () use ($resource) {
return $resource->lexical_entry;
}
]
];
}