Magento 2 - How to get attribute options value of eav entity?

How can I get the attribute options values of eav entity?
I found solution only for magento 1.x but M2 I don't know.

$attr = Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter('specialty')->getData()[0];
$attributeModel = Mage::getModel('eav/entity_attribute')->load($attr['attribute_id']);
$src =  $attributeModel->getSource()->getAllOptions();

Anyone know, show me step by step, pls!Thanks!


Use the following code to get all attribute options.

function getExistingOptions( $object_Manager ) {

$eavConfig = $object_Manager->get('\Magento\Eav\Model\Config');
$attribute = $eavConfig->getAttribute('catalog_product', 'color');
$options = $attribute->getSource()->getAllOptions();

$optionsExists = array();

foreach($options as $option) {
    $optionsExists[] = $option['label'];

return $optionsExists;


Please Can you click here for more detailed explanation.

you can add to the constructor of your class an instance of \Magento\Eav\Model\Config like this:

protected $eavConfig;
public function __construct(
    \Magento\Eav\Model\Config $eavConfig,
    $this->eavConfig = $eavConfig;

then you can use that in your class

$attribute = $this->eavConfig->getAttribute('catalog_product', 'attribute_code_here');
$options = $attribute->getSource()->getAllOptions();

You can do it simply call below code inside your Block file.

namespace Vendor\Package\Block;

class Blockname extends \Magento\Framework\View\Element\Template
    protected $_productAttributeRepository;

    public function __construct(        
        \Magento\Framework\View\Element\Template\Context $context,   
        \Magento\Catalog\Model\Product\Attribute\Repository $productAttributeRepository,
        array $data = [] 
        $this->_productAttributeRepository = $productAttributeRepository;

    public function getAllBrand(){
        $manufacturerOptions = $this->_productAttributeRepository->get('manufacturer')->getOptions();       
        $values = array();
        foreach ($manufacturerOptions as $manufacturerOption) { 
           //$manufacturerOption->getValue();  // Value
            $values[] = $manufacturerOption->getLabel();  // Label
        return $values;

Call inside your phtml file,

<div class="manufacturer-name">
      <?php $getOptionValue = $this->getAllBrand();?>
      <?php foreach($getOptionValue as $value){ ?>
           <span><?php echo $value;?></span>
      <?php } ?>


Similar questions

How to override Magento\Eav\Model\ResourceModel\Entity\Attribute class methods in Magento 2.2?
I have tried to override _processAttributeOptions() method from Magento\Eav\Model\ResourceModel\Entity\Attribute in my custom module. But the function does not override. Here is my code: Namespace\Module_Name\etc\di.xml Namespace\Module_Name\Model\ResourceModel\Entity\Attribute Please help me to override this method in Magento 2.2.
Magento 2 : Invalid method Magento\Eav\Model\Entity\Attribute::isScopeStore
I am getting an issue on Magento 2.2.6 when trying to save my module record. This error occurs sometimes and the error disappears if run Magento upgrade command. But it comes again sometime. system.log : /app/code/VendorName/ModuleName/Model/ResourceModel/EntityName.php what should I need to change ? Any help would be appriciated. Thanks in advance...
Call to undefined method Magento\Eav\Model\Entity\Attribute\Source\Boolean::getSpecificOptions()
I'm getting the following error when listing the products in a category: It's just the standard page that the topmenu takes you to when clicking on a category. Could anyone point me in the right direction to resolve this issue?
Invalid method Magento\Eav\Model\Entity\Attribute::canBeFilterableInGrid when accesing customer_grid in the administration
This error is pretty strange, how come that when I try to access the customer grid all of the sudden it is throwing me this error? I checked that class and the method does not exist.
Update Product programmatically - Invalid method Magento\Eav\Model\Entity\Attribute::isScopeGlobal
I have a quite simple piece of code (reduced it to that): and it outputs this: ... I have no clue why this could happen. Any ideas?
strpos() expects parameter 1 to be string, array given in vendor/magento/module-eav/Model/Entity/Attribute/Source/Table.php on line 160
I am getting following error on product detail page for multiselect attributes. I am using magento 2.2.3 please help

Also ask

We use cookies to deliver the best possible experience on our website. By continuing to use this site, accepting or closing this box, you consent to our use of cookies. To learn more, visit our privacy policy.