Element API - Entries Related to a Category In Craft 3, I want to list all the categories in a group and all the entries related to them. How can I do this?
The slower but easier approach is to fetch all of them and search for related entries

'elementType' =&gt; Category::class,
'criteria'    =&gt; [
    'group'   =&gt; 'yourGroup', 
],
'paginate'    =&gt; false,
'transformer' =&gt; function(Category $category) {
     $entries = Entry::find()
        -&gt;relatedTo($category)
        -&gt;select(['title'])
        -&gt;asArray()
        -&gt;column();

    return [
        'title'   =&gt; $category-&gt;title,
        'entries' =&gt; $entries     
    ];
}


Learn more about Element Queries especially the different ways to fetch entries via one(), all(), column()