I created a custom database table and now want to fetch data, but getCollection method is deprecated and I can't find any other method that suits my case. Here's the example of my code:
use Magento\Customer\Model\ResourceModel\Customer\CollectionFactory;
use <MyName>\<MyModule>\Model\UserUpdateFactory;
class CustomerChangeTracker {
private $customer;
private $previousCustomer;
private $current = [];
public function __construct(CollectionFactory $customer, UserUpdateFactory $previousCustomer)
{
$this->customer = $customer;
$this->previousCustomer = $previousCustomer;
}
public function getChangesSinceLastTime(): array
{
$current = [];
$collection = $this->customer->create();
foreach ($collection as $customer) {
$current[$customer->getId()] = $customer->getData('updated_at');
}
$this->setCurrent($current);
$previous = [];
foreach ($this->previousCustomer->create()->getCollection() as $customer) {
$previous[$customer->getData('customer_id')] = $customer->getData('updated_at');
}