Magento 2 – Custom Product Attribute in Product Collection

collection;magento2product-collection

I've created a new product attribute 'brand'. This attribute is within my default attribute set. Now I'm trying to get all brands from a product collection within a category.

I'm fetching the product collection:

$products = $this->_productCollectionFactory
    ->addAttributeToSelect('brand')
    ->addCategoryFilter($activeCategory)
    ->load();

But the brand is not displayed? The attribute brand is just a simpel text attribute. How can I fetch all brands from this collection?

Thanks

Best Answer

Based on the comments...
when using an attribute in a product collection, if the flat catalog is enabled, the attribute must be marked as Used in product listing in order to be picked up by the collection.