How to get Customer collection filter by Full name or by keyword like admin grid of magento 2?

enter image description here


First, you have to call the Customer Collection factory and after that add addNameToSelect() function to that collection.

namespace {nameSpace};

class CustomCollection
    protected  $collectionFactory;
    public function __construct(
        \Magento\Customer\Model\ResourceModel\Customer\CollectionFactory $collectionFactory
        $this->collectionFactory = $collectionFactory;

    public function getCustomCollectionWithFullName()
        $customerName = 'John';
        $customerCollection = $this->collectionFactory->create();
        $customerCollection->addAttributeToSelect('*'); // use * for all field
        // for == condition
        $customerCollection->getSelect() ->where(
            'name = ?',
        // where like %V%

       // $customerCollection->where('name LIKE ?', '%' . $customerName . '%');



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.