I think the best function suits your needs queryBy(), because it returns an array of matching records.
You can still use each()to check if the model meets the criteria and then add them to the array. But this function is more suitable for moving all records in the repository, and not just for “filtering” data.
source
share