When you want to save data in a module, you may want to store that in a custom entity. That entity needs a database table and a model that talks with that database table.
We will create a subscriptions entity where we can store subscriptions.
In this recipe, we will extend the module of Chapter 4, Creating a Module, with an entity with a database table. Make sure you have the starter files for this recipe installed.
In the next steps, we will learn how we can add entities to an existing module:
When installing a new entity, we have to create a resource model. We can do this by creating the file
app/code/Packt/HelloWorld/Model/ResourceModel/Subscription.php
with the following content:<?php namespace Packt\HelloWorld\Model\ResourceModel; class Subscription extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb { public function _construct() { $this->_init('packt_helloworld_subscription', 'subscription_id'); } }
The...