Load data with a resource model in Magento
Learn how to load Magento blog post data by ID using a resource model and PostRepository.
Lesson Content
Weโre going to retrieve data for our repository using a resource model. While weโre doing this to complete our data repository class, the same approach applies across Magento. You can always use a resource model to fetch data from the database. Once you write data methods on a repository, the implementation details are abstracted away, giving you a public API for yourself and others to use later.
Weโll create an instance of a post by calling the PostFactory, then retrieve data using a resource model. So, weโll need to inject both of those classes into the constructor:
Join the discussion!
Comments
Want to comment on this lesson?
Enroll in this course to leave comments.