Overview

There is an convenience method on Filter::relation that allows you to easily define nested relationships.

public function allowedFilters(): AllowedFilterList
{
    return Filter::only(
        Filter::relation('posts', [FilterType::HAS])->includeRelationFields()
            ->andNestedRelation(
                Filter::relation('comments', [FilterType::HAS])->includeRelationFields()
            ),
    );
}