Save data using a repository in Magento
Learn how to save data using a repository in a Magento 2 setup patch with PostFactory and PostRepositoryInterface.
Lesson Content
Letโs use our newly created repository to save data within our setup patch data script. Within this apply function is where our code will go. But first, we need to inject some classes into the constructor.
Weโll need to create Post objects, so letโs inject a PostFactory class. Since this is an auto-generated class and doesnโt exist until runtime, we will need to define a manual import at the (very) top of this file. We'll also import the PostRepositoryInterface class:
<?php
declare(strict_types=1);
names...
Join the discussion!
Comments
Want to comment on this lesson?
Enroll in this course to leave comments.