Write a setup patch data script in Magento
Learn how to write a Magento setup patch data script to populate blog posts in a custom module.
Lesson Content
Now that we have a database table set up for our blog posts, it makes sense to populate it with some data. This lets us test how to query data and display it on the frontend of our site.
Data is populated with patch data scripts. Create a folder for these scripts at Setup/Patch/Data. The name of this PHP class should be descriptive about what the script does, so we’ll name it PopulateBlogPosts.
Open the PHP tag, declare strict types, and set the namespace to Macademy\Blog\Setup\Patch\Data. Then create the PopulateBlogPosts class, and have it implement the DataPatchInterface fro...
Join the discussion!
Comments
Want to comment on this lesson?
Enroll in this course to leave comments.