With v2 of the Element API plugin, I'm having issues with working out how to return entries that are in a particular category.
I've got the slug in the API route but can't work out what the query should be in the transformer.
Should I be doing this query in a total different way? I keep thinking I've just gone down the wrong way to do it completely.
'api/v1/category/<slug:{slug}>.json' => function($slug) {
return [
'elementType' => Entry::class,
'elementsPerPage' => 30,
'criteria' => [
'section' => 'posts',
'relatedTo' => ['targetElement' => ***category slug($slug)***],
],
'transformer' => function(Entry $entry) {
return [
'title' => $entry->title,
'id' => (int) $entry->id,
'slug' => $entry->slug,
'postDate' => $entry->postDate
];
},
'pretty' => true
];
}