Task: Implement a Fractal transformer for Rating models
What to implement
Create a new class at /app/Transformer/RatingTransformer.php.
The class should be named RatingTransformer and extend League\Fractal\TransformerAbstract.
Implement a transform($rating) method that converts a Rating model into a Fractal-friendly array with the following structure:
id: the rating's id
value: the rating's value
type: the rating's rateable_type (as stored on the rating)
links: an array containing a single link describing the rateable author, e.g.:
rel: "author"
href: the URL for the author show route, obtained via route('authors.show', ['id' => $author->id])
The transformer must support transforming ratings whose rateable_type is App\Author (the test creates an Author and associates a Rating via a morphMany/morphTo relationship). For any other rateable_type, the transformer must throw a RuntimeException with the exact message:
Rateable model type for <TYPE> is not defined
where <TYPE> is the rating's rateable_type (e.g., Foo\Bar).
Implementation details:
Access the related author via the rating's rateable relationship (e.g., $rating->rateable). This link should be used to build the href with route('authors.show', ['id' => $author->id]).
The returned array must match the test expectations:
'id' equals $rating->id
'value' equals $rating->value
'type' equals $rating->rateable_type
'links' contains exactly one element with 'rel' => 'author' and 'href' equal to route('authors.show', ['id' => $author->id])
Notes
The tests expect App\Author to be the supported rateable type; ensure the transformer throws the specified exception for any other rateable_type (e.g., Foo\Bar).
Do not modify tests or other models; only add the transformer class in the specified path.