I am having trouble getting the related category passed thru to the entry api endpoint.
I cant use :
$criteria = craft()->elements->getCriteria(ElementType::Category);
$criteria->id = $catId;
$category = $criteria->first();
What is the equivalent in craft 3 api v2?
'api/v1/ship/category/<catId:\d+>.json' => function($catId) {
//old api craft 2
$criteria = craft()->elements->getCriteria(ElementType::Category);
$criteria->id = $catId;
$category = $criteria->first();
//api craft 3
return [
'elementType' => Entry::class,
'elementsPerPage' => 30,
'criteria' => [
'criteria' => ['section' => 'ship'],
'relatedTo' => ['targetElement' => $category],
],
'transformer' => function(Entry $entry) {
return [
'title' => $entry->title,
'id' => (int) $entry->id,
'slug' => $entry->slug,
'postDate' => $entry->postDate
];
},
'pretty' => true
];
},