Start your All-Access Pass to unlock this challenge
Suppose we have a Product
entity with the following category
property:
#[ApiResource(normalizationContext: ['groups' => 'product:read']]
class Product
{
// ...
#[Groups('product:read')]
public Category $category;
}
And Category
looks like this:
#[ApiResource(normalizationContext: ['groups' => 'category:read']]
class Category
{
// ...
#[Groups('category:read')]
public string $name;
}
Right now, when you make a GET
request to /api/products/3
, the response looks like this:
{
"@id": "/api/products/3",
"@type": "Product",
"category": "/api/categories/5"
}
Instead of the IRI, what is the easiest way to turn the category
field into an object with the category's name
inside?