Associations
The associations callback is used to define the relationships that one schema
has with other schemas. Associations are defined as follows:
public function associations(): array
{
return [
'posts' => $this->association('blog_posts', PostSchema::class),
];
}
Here, we've declared a new association that is available to clients by the name
of posts. This association uses the blog_posts key on the model (that was
defined in the model()) callback to fetch the data. This related data can then
be rendered using the PostSchema class.
Documentation
The description method can be used to add documentation to an association that
will be displayed in the generated documentation page:
public function associations(): array
{
return [
'posts' => $this->association('posts', PostSchema::class)->description('blog posts'),
];
}