{"id":297489,"date":"2021-07-28T04:45:39","date_gmt":"2021-07-28T04:45:39","guid":{"rendered":"https:\/\/webkul.com\/blog\/?p=297489"},"modified":"2024-11-12T05:47:15","modified_gmt":"2024-11-12T05:47:15","slug":"magento-2-development-21-loading-magentos-data","status":"publish","type":"post","link":"https:\/\/webkul.com\/blog\/magento-2-development-21-loading-magentos-data\/","title":{"rendered":"Magento 2 Development 24: Loading Magento&#8217;s Data"},"content":{"rendered":"\n<p>We&#8217;ve explored how to use custom table collections in Magento. Magento already has models and collections for things like customers, products, and orders.<\/p>\n\n\n\n<p>In this blog, we\u2019ll focus on using customer and product collections. At the end, I\u2019ll share some recommended exercises to help you deepen your understanding. <\/p>\n\n\n\n<p>These exercises are based on practices from a <a href=\"https:\/\/webkul.com\/magento-development\/\" target=\"_blank\" rel=\"noreferrer noopener\">Magento development company<\/a>, so be sure to try them out!<\/p>\n\n\n\n<p>In this blog, we will allow the admin to assign a blog to any author. Also, the admin will be able to add related products to the blog. <\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Customer Collection<\/h3>\n\n\n\n<p>We will add the assign author feature in the status tab only. So let&#8217;s edit the <em>Block\/Adminhtml\/Blog\/Edit\/Tab\/Status.php<\/em><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">&lt;?php\nnamespace Webkul\\BlogManager\\Block\\Adminhtml\\Blog\\Edit\\Tab;\n\nclass Status extends \\Magento\\Backend\\Block\\Widget\\Form\\Generic\n{\n    \/**\n     * @var \\Webkul\\BlogManager\\Model\\Blog\\Status\n     *\/\n    protected $blogStatus;\n\n    \/**\n     * @var \\Magento\\Customer\\Model\\CustomerFactory\n     *\/\n    protected $customerFactory;\n\n    \/**\n     * Dependency Initilization\n     *\n     * @param \\Magento\\Backend\\Block\\Template\\Context $context\n     * @param \\Magento\\Framework\\Registry $registry\n     * @param \\Magento\\Framework\\Data\\FormFactory $formFactory\n     * @param \\Webkul\\BlogManager\\Model\\Blog\\Status $blogStatus\n     * @param \\Magento\\Customer\\Model\\CustomerFactory $customerFactory\n     * @param array $data\n     *\/\n    public function __construct(\n        \\Magento\\Backend\\Block\\Template\\Context $context,\n        \\Magento\\Framework\\Registry $registry,\n        \\Magento\\Framework\\Data\\FormFactory $formFactory,\n        \\Webkul\\BlogManager\\Model\\Blog\\Status $blogStatus,\n        \\Magento\\Customer\\Model\\CustomerFactory $customerFactory,\n        array $data = &#091;]\n    ) {\n        $this-&gt;blogStatus = $blogStatus;\n        $this-&gt;customerFactory = $customerFactory;\n        parent::__construct($context, $registry, $formFactory, $data);\n    }\n\n    \/**\n     * Prepare form data\n     *\n     * @return \\Magento\\Backend\\Block\\Widget\\Form\n     *\/\n    protected function _prepareForm()\n    {\n        $model = $this-&gt;_coreRegistry-&gt;registry(&#039;blog_data&#039;);\n\n        $form = $this-&gt;_formFactory-&gt;create();\n\n        $form-&gt;setHtmlIdPrefix(&#039;blogmanager_&#039;);\n\n        $fieldset = $form-&gt;addFieldset(\n            &#039;base_fieldset&#039;,\n            &#091;&#039;legend&#039; =&gt; __(&#039;Edit Blog&#039;), &#039;class&#039; =&gt; &#039;fieldset-wide&#039;]\n        );\n\n        $fieldset-&gt;addField(\n            &#039;status&#039;,\n            &#039;select&#039;,\n            &#091;\n                &#039;name&#039; =&gt; &#039;status&#039;,\n                &#039;label&#039; =&gt; __(&#039;Status&#039;),\n                &#039;options&#039; =&gt; &#091;0=&gt;__(&#039;Disabled&#039;), 1=&gt;__(&#039;Enabled&#039;)],\n                &#039;id&#039; =&gt; &#039;status&#039;,\n                &#039;title&#039; =&gt; __(&#039;Status&#039;),\n                &#039;class&#039; =&gt; &#039;required-entry&#039;,\n                &#039;required&#039; =&gt; true,\n            ]\n        );\n\n        $fieldset-&gt;addField(\n            &#039;user_id&#039;,\n            &#039;select&#039;,\n            &#091;\n                &#039;name&#039; =&gt; &#039;user_id&#039;,\n                &#039;label&#039; =&gt; __(&#039;Author&#039;),\n                &#039;options&#039; =&gt; $this-&gt;getAuthorOptions(),\n                &#039;id&#039; =&gt; &#039;user_id&#039;,\n                &#039;title&#039; =&gt; __(&#039;Author&#039;),\n                &#039;class&#039; =&gt; &#039;required-entry&#039;,\n                &#039;required&#039; =&gt; true,\n            ]\n        );\n\n        $form-&gt;setValues($model-&gt;getData());\n        $this-&gt;setForm($form);\n\n        return parent::_prepareForm();\n    }\n\n    \/**\n     * Provides Author options\n     *\n     * @return array\n     *\/\n    private function getAuthorOptions()\n    {\n        $collection = $this-&gt;customerFactory-&gt;create()-&gt;getCollection();\n        $authors = &#091;0=&gt;&#039;Admin&#039;];\n        foreach ($collection as $model) {\n            $authors&#091;$model-&gt;getId()] = $model-&gt;getName();\n        }\n        return $authors;\n    }\n}<\/pre>\n\n\n\n<p>We have used <strong><code>\\Magento\\Customer\\Model\\CustomerFactory<\/code><\/strong> which is a model for customer data. <\/p>\n\n\n\n<p>And in the <strong>getAuthorOptions<\/strong> function, we have loaded the collection through the model.<\/p>\n\n\n\n<p>After that, we created an associative array of <strong>$authors<\/strong> which will be used for options. In the <strong>$authors<\/strong> array we have added an entry for admin too with the id as 0.<\/p>\n\n\n\n<p>Note that we could have also used the collection class <strong>\\Magento\\Customer\\Model\\ResourceModel\\Customer\\CollectionFactory<\/strong>.<\/p>\n\n\n\n<p>Now you will see the field as shown below,<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1200\" height=\"526\" src=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/07\/2021-07-22_16-22-1200x526.png\" alt=\"2021-07-22_16-22\" class=\"wp-image-297656\" srcset=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/07\/2021-07-22_16-22-1200x526.png 1200w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/07\/2021-07-22_16-22-300x132.png 300w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/07\/2021-07-22_16-22-250x110.png 250w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/07\/2021-07-22_16-22-768x337.png 768w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/07\/2021-07-22_16-22-1536x674.png 1536w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/07\/2021-07-22_16-22.png 1799w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" loading=\"lazy\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><br>Product Collection<\/h3>\n\n\n\n<p>Let&#8217;s add the related product feature. For that, we will create a new tab which means we will have to edit the <em>Block\/Adminhtml\/Blog\/Edit\/Tabs.php<\/em><\/p>\n\n\n\n<p>Updated code for <em>Block\/Adminhtml\/Blog\/Edit\/Tabs.php<\/em> file<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">&lt;?php\nnamespace Webkul\\BlogManager\\Block\\Adminhtml\\Blog\\Edit;\n\nclass Tabs extends \\Magento\\Backend\\Block\\Widget\\Tabs\n{\n    \/**\n     * @var \\Magento\\Framework\\Registry\n     *\/\n    protected $_coreRegistry;\n\n    \/**\n     * Dependency Initilization\n     *\n     * @param \\Magento\\Backend\\Block\\Template\\Context $context\n     * @param \\Magento\\Framework\\Json\\EncoderInterface $jsonEncoder\n     * @param \\Magento\\Backend\\Model\\Auth\\Session $authSession\n     * @param \\Magento\\Framework\\Registry $coreRegistry\n     * @param array $data\n     *\/\n    public function __construct(\n        \\Magento\\Backend\\Block\\Template\\Context $context,\n        \\Magento\\Framework\\Json\\EncoderInterface $jsonEncoder,\n        \\Magento\\Backend\\Model\\Auth\\Session $authSession,\n        \\Magento\\Framework\\Registry $coreRegistry,\n        array $data = &#091;]\n    ) {\n        $this-&gt;_coreRegistry = $coreRegistry;\n        parent::__construct($context, $jsonEncoder, $authSession, $data);\n    }\n\n    \/**\n     * Dependency Initilization\n     *\n     * @return void\n     *\/\n    protected function _construct()\n    {\n        parent::_construct();\n        $this-&gt;setId(&#039;blog_tabs&#039;);\n        $this-&gt;setDestElementId(&#039;edit_form&#039;);\n        $this-&gt;setTitle(__(&#039;Blog Data&#039;));\n    }\n\n    \/**\n     * Prepare form data\n     *\n     * @return \\Magento\\Backend\\Block\\Widget\\Form\n     *\/\n    protected function _prepareLayout()\n    {\n        $this-&gt;addTab(\n            &#039;main&#039;,\n            &#091;\n                &#039;label&#039; =&gt; __(&#039;Blog Data&#039;),\n                &#039;content&#039; =&gt; $this-&gt;getLayout()-&gt;createBlock(\n                    &#039;Webkul\\BlogManager\\Block\\Adminhtml\\Blog\\Edit\\Tab\\Main&#039;\n                )-&gt;toHtml(),\n                &#039;active&#039; =&gt; true\n            ]\n        );\n\n        $this-&gt;addTab(\n            &#039;status&#039;,\n            &#091;\n                &#039;label&#039; =&gt; __(&#039;Blog Status&#039;),\n                &#039;content&#039; =&gt; $this-&gt;getLayout()-&gt;createBlock(\n                    &#039;Webkul\\BlogManager\\Block\\Adminhtml\\Blog\\Edit\\Tab\\Status&#039;\n                )-&gt;toHtml()\n            ]\n        );\n\n        $this-&gt;addTab(\n            &#039;related_products&#039;,\n            &#091;\n                &#039;label&#039; =&gt; __(&#039;Related Products&#039;),\n                &#039;content&#039; =&gt; $this-&gt;getLayout()-&gt;createBlock(\n                    &#039;Webkul\\BlogManager\\Block\\Adminhtml\\Blog\\Edit\\Tab\\RelatedProducts&#039;\n                )-&gt;toHtml()\n            ]\n        );\n\n        return parent::_prepareLayout();\n    }\n}<\/pre>\n\n\n\n<p>Here we have just added a new tab with <strong><code>$this-&gt;addTab<\/code><\/strong> function. <\/p>\n\n\n\n<p>Now let&#8217;s write code for the related products tab. We will create the class as <em>Block\/Adminhtml\/Blog\/Edit\/Tab\/RelatedProducts.php<\/em><\/p>\n\n\n\n<p>Code  for <em>Block\/Adminhtml\/Blog\/Edit\/Tab\/RelatedProducts.php<\/em> file<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">&lt;?php\nnamespace Webkul\\BlogManager\\Block\\Adminhtml\\Blog\\Edit\\Tab;\n\nclass RelatedProducts extends \\Magento\\Backend\\Block\\Widget\\Form\\Generic\n{\n    \/**\n     * @var \\Magento\\Catalog\\Model\\ResourceModel\\Product\\CollectionFactory\n     *\/\n    protected $productCollectionFactory;\n\n    \/**\n     * Dependency Initilization\n     *\n     * @param \\Magento\\Backend\\Block\\Template\\Context $context\n     * @param \\Magento\\Framework\\Registry $registry\n     * @param \\Magento\\Framework\\Data\\FormFactory $formFactory\n     * @param \\Magento\\Catalog\\Model\\ResourceModel\\Product\\CollectionFactory $productCollectionFactory\n     * @param array $data\n     *\/\n    public function __construct(\n        \\Magento\\Backend\\Block\\Template\\Context $context,\n        \\Magento\\Framework\\Registry $registry,\n        \\Magento\\Framework\\Data\\FormFactory $formFactory,\n        \\Magento\\Catalog\\Model\\ResourceModel\\Product\\CollectionFactory $productCollectionFactory,\n        array $data = &#091;]\n    ) {\n        $this-&gt;productCollectionFactory = $productCollectionFactory;\n        parent::__construct($context, $registry, $formFactory, $data);\n    }\n\n    \/**\n     * Prepare form data\n     *\n     * @return \\Magento\\Backend\\Block\\Widget\\Form\n     *\/\n    protected function _prepareForm()\n    {\n       \n        $model = $this-&gt;_coreRegistry-&gt;registry(&#039;blog_data&#039;);\n\n        $form = $this-&gt;_formFactory-&gt;create();\n\n        $form-&gt;setHtmlIdPrefix(&#039;blogmanager_&#039;);\n\n        $fieldset = $form-&gt;addFieldset(\n            &#039;base_fieldset&#039;,\n            &#091;&#039;legend&#039; =&gt; __(&#039;Related Products&#039;), &#039;class&#039; =&gt; &#039;fieldset-wide&#039;]\n        );\n\n        $fieldset-&gt;addField(\n            &#039;products&#039;,\n            &#039;multiselect&#039;,\n            &#091;\n                &#039;name&#039; =&gt; &#039;products&#039;,\n                &#039;label&#039; =&gt; __(&#039;Products&#039;),\n                &#039;values&#039; =&gt; $this-&gt;getProductOptions(),\n                &#039;id&#039; =&gt; &#039;products&#039;,\n                &#039;title&#039; =&gt; __(&#039;Products&#039;),\n                &#039;required&#039; =&gt; false,\n            ]\n        );\n\n        $form-&gt;setValues($model-&gt;getData());\n        $this-&gt;setForm($form);\n\n        return parent::_prepareForm();\n    }\n\n    \/**\n     * Get Product Options\n     *\n     * @return array\n     *\/\n    private function getProductOptions()\n    {\n        $collection = $this-&gt;productCollectionFactory-&gt;create()-&gt;addAttributeToSelect(&#039;name&#039;);\n        $products = &#091;];\n        foreach ($collection as $model) {\n            $products&#091;] = &#091;&#039;value&#039;=&gt;$model-&gt;getId(), &#039;label&#039;=&gt;$model-&gt;getName()];\n        }\n        return $products;\n    }\n}<\/pre>\n\n\n\n<p>Here we have used the products collection class which is <strong>\\Magento\\Catalog\\Model\\ResourceModel\\Product\\CollectionFactory<\/strong><\/p>\n\n\n\n<p>but could have also used the model which is <strong>\\Magento\\Catalog\\Model\\ProductFactory<\/strong>.<\/p>\n\n\n\n<p>One more thing to note here is <strong>-&gt;addAttributeToSelect(&#8216;name&#8217;)<\/strong> since there is a lot of data for a product. <\/p>\n\n\n\n<p>By default, Magento only loads basic details such as id, sku, type, etc. So we have to use <strong><strong>addAttributeToSelect<\/strong><\/strong> to load the additional fields such as name here.<\/p>\n\n\n\n<p>Also please note that it is a multi-select type field so the syntax for the field and option is a little bit different than what we have seen so far.<\/p>\n\n\n\n<p>Now you should see the related products tab like,<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1200\" height=\"612\" src=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/07\/2021-07-22_16-44-1200x612.png\" alt=\"2021-07-22_16-44\" class=\"wp-image-297659\" srcset=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/07\/2021-07-22_16-44-1200x612.png 1200w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/07\/2021-07-22_16-44-300x153.png 300w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/07\/2021-07-22_16-44-250x128.png 250w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/07\/2021-07-22_16-44-768x392.png 768w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/07\/2021-07-22_16-44-1536x784.png 1536w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/07\/2021-07-22_16-44.png 1826w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" loading=\"lazy\" \/><\/figure>\n\n\n\n<p><br>It looks well and good but we won&#8217;t be able to save the data yet. First of all, we will have to create a new column in the table for the related products.<\/p>\n\n\n\n<p>Also, we have to modify the save controller a little bit.<\/p>\n\n\n\n<p>To add the column let&#8217;s modify the db schema <em>etc\/db_schema.xml<\/em><\/p>\n\n\n\n<p>Updated code for db schema <em>etc\/db_schema.xml<\/em> file<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">&lt;?xml version=&quot;1.0&quot;?&gt;\n&lt;schema xmlns:xsi=&quot;http:\/\/www.w3.org\/2001\/XMLSchema-instance&quot; xsi:noNamespaceSchemaLocation=&quot;urn:magento:framework:Setup\/Declaration\/Schema\/etc\/schema.xsd&quot;&gt;\n    &lt;table name=&quot;blogmanager_blog&quot; resource=&quot;default&quot; engine=&quot;innodb&quot; comment=&quot;Blogs Table&quot;&gt;\n        &lt;column xsi:type=&quot;int&quot; name=&quot;entity_id&quot; padding=&quot;10&quot; unsigned=&quot;true&quot; nullable=&quot;false&quot; identity=&quot;true&quot; comment=&quot;Entity Id&quot;\/&gt;\n        &lt;column xsi:type=&quot;int&quot; name=&quot;user_id&quot; padding=&quot;10&quot; unsigned=&quot;true&quot; nullable=&quot;false&quot; comment=&quot;Customer\/User Id&quot;\/&gt;\n        &lt;column xsi:type=&quot;varchar&quot; name=&quot;title&quot; nullable=&quot;false&quot; length=&quot;255&quot; comment=&quot;Blog Title&quot;\/&gt;\n        &lt;column xsi:type=&quot;longtext&quot; name=&quot;content&quot; nullable=&quot;false&quot; comment=&quot;Blog Content&quot;\/&gt;\n        &lt;column xsi:type=&quot;smallint&quot; name=&quot;status&quot; padding=&quot;11&quot; unsigned=&quot;false&quot; nullable=&quot;false&quot; default=&quot;0&quot; comment=&quot;Blog Status&quot;\/&gt;\n        &lt;column xsi:type=&quot;timestamp&quot; name=&quot;created_at&quot; on_update=&quot;false&quot; nullable=&quot;false&quot; default=&quot;CURRENT_TIMESTAMP&quot; comment=&quot;Creation Time&quot;\/&gt;\n        &lt;column xsi:type=&quot;timestamp&quot; name=&quot;updated_at&quot; on_update=&quot;true&quot; nullable=&quot;false&quot; default=&quot;CURRENT_TIMESTAMP&quot; comment=&quot;Updated At&quot;\/&gt;\n        &lt;column xsi:type=&quot;varchar&quot; name=&quot;products&quot; nullable=&quot;false&quot; length=&quot;255&quot; comment=&quot;Related products&quot;\/&gt;\n        &lt;constraint xsi:type=&quot;primary&quot; referenceId=&quot;PRIMARY&quot;&gt;\n            &lt;column name=&quot;entity_id&quot;\/&gt;\n        &lt;\/constraint&gt;\n        &lt;index referenceId=&quot;BLOGMANAGER_BLOG_USER_ID&quot; indexType=&quot;btree&quot;&gt;\n            &lt;column name=&quot;user_id&quot;\/&gt;\n        &lt;\/index&gt;\n    &lt;\/table&gt;\n    &lt;table name=&quot;blogmanager_comment&quot; resource=&quot;default&quot; engine=&quot;innodb&quot; comment=&quot;Blog Comments Table&quot;&gt;\n        &lt;column xsi:type=&quot;int&quot; name=&quot;entity_id&quot; padding=&quot;10&quot; unsigned=&quot;true&quot; nullable=&quot;false&quot; identity=&quot;true&quot; comment=&quot;Entity Id&quot;\/&gt;\n        &lt;column xsi:type=&quot;int&quot; name=&quot;blog_id&quot; padding=&quot;10&quot; unsigned=&quot;true&quot; nullable=&quot;false&quot; comment=&quot;Blog Id&quot;\/&gt;\n        &lt;column xsi:type=&quot;int&quot; name=&quot;user_id&quot; padding=&quot;10&quot; unsigned=&quot;true&quot; nullable=&quot;false&quot; comment=&quot;User Id&quot;\/&gt;\n        &lt;column xsi:type=&quot;varchar&quot; name=&quot;screen_name&quot; nullable=&quot;false&quot; length=&quot;255&quot; comment=&quot;Screen Name&quot;\/&gt;\n        &lt;column xsi:type=&quot;text&quot; name=&quot;comment&quot; nullable=&quot;false&quot; comment=&quot;Comment&quot;\/&gt;\n        &lt;column xsi:type=&quot;smallint&quot; name=&quot;status&quot; padding=&quot;11&quot; unsigned=&quot;false&quot; nullable=&quot;false&quot; default=&quot;0&quot; comment=&quot;Status&quot;\/&gt;\n        &lt;column xsi:type=&quot;timestamp&quot; name=&quot;created_at&quot; on_update=&quot;false&quot; nullable=&quot;false&quot; default=&quot;CURRENT_TIMESTAMP&quot; comment=&quot;Creation Time&quot;\/&gt;\n        &lt;constraint xsi:type=&quot;primary&quot; referenceId=&quot;PRIMARY&quot;&gt;\n            &lt;column name=&quot;entity_id&quot;\/&gt;\n        &lt;\/constraint&gt;\n        &lt;constraint xsi:type=&quot;foreign&quot; referenceId=&quot;FK_BLOG_COMMENT&quot; table=&quot;blogmanager_comment&quot; column=&quot;blog_id&quot; referenceTable=&quot;blogmanager_blog&quot; referenceColumn=&quot;entity_id&quot; onDelete=&quot;CASCADE&quot;\/&gt;\n        &lt;index referenceId=&quot;BLOGMANAGER_COMMENT_BLOG_ID&quot; indexType=&quot;btree&quot;&gt;\n            &lt;column name=&quot;blog_id&quot;\/&gt;\n        &lt;\/index&gt;\n    &lt;\/table&gt;\n&lt;\/schema&gt;<\/pre>\n\n\n\n<p>We have just added a column tag to add the column and the name of the column is <strong>products<\/strong>. Now we have to run these commands if you recall from <a href=\"https:\/\/webkul.com\/blog\/magento-development-03-creating-tables\/\" target=\"_blank\" rel=\"noreferrer noopener\">Magento 2 Development 03: Creating Tables<\/a> blog.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">php bin\/magento setup:db-declaration:generate-whitelist --module-name=Webkul_BlogManager\n\nphp bin\/magento setup:upgrade\n\nNow we have to write code to save the values in db. So we will edit &lt;em&gt;Controller\/Adminhtml\/Manage\/Save.php&lt;\/em&gt;<\/pre>\n\n\n\n<p>Updated code for <em>Controller\/Adminhtml\/Manage\/Save.php<\/em> file<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">&lt;?php\nnamespace Webkul\\BlogManager\\Controller\\Adminhtml\\Manage;\n\nuse Magento\\Backend\\App\\Action;\nuse Magento\\Backend\\App\\Action\\Context;\n\nclass Save extends Action\n{\n    \/**\n     * @var \\Webkul\\BlogManager\\Model\\BlogFactory\n     *\/\n    protected $blogFactory;\n\n    \/**\n     * Dependency Initilization\n     *\n     * @param Context $context\n     * @param \\Webkul\\BlogManager\\Model\\BlogFactory $blogFactory\n     *\/\n    public function __construct(\n        Context $context,\n        \\Webkul\\BlogManager\\Model\\BlogFactory $blogFactory\n    ) {\n        $this-&gt;blogFactory = $blogFactory;\n        parent::__construct($context);\n    }\n\n    \/**\n     * Provides content\n     *\n     * @return Magento\\Framework\\Controller\\Result\\Redirect\n     *\/\n    public function execute()\n    {\n        $resultRedirect = $this-&gt;resultRedirectFactory-&gt;create();\n        $data = $this-&gt;getRequest()-&gt;getParams();\n        if (isset($data&#091;&#039;entity_id&#039;]) &amp;&amp; $data&#091;&#039;entity_id&#039;]) {\n            $model = $this-&gt;blogFactory-&gt;create()-&gt;load($data&#091;&#039;entity_id&#039;]);\n            $model-&gt;setTitle($data&#091;&#039;title&#039;])\n                -&gt;setContent($data&#091;&#039;content&#039;])\n                -&gt;setStatus($data&#091;&#039;status&#039;])\n                -&gt;setUserId($data&#091;&#039;user_id&#039;]);\n            if (isset($data&#091;&#039;products&#039;])) {\n                $model-&gt;setProducts(implode(&#039;,&#039;, $data&#091;&#039;products&#039;]));\n            } else {\n                $model-&gt;setProducts(&#039;&#039;);\n            }\n            $model-&gt;save();\n            $this-&gt;messageManager-&gt;addSuccess(__(&#039;You have updated the blog successfully.&#039;));\n        } else {\n            $model = $this-&gt;blogFactory-&gt;create();\n            $model-&gt;setTitle($data&#091;&#039;title&#039;])\n                -&gt;setContent($data&#091;&#039;content&#039;])\n                -&gt;setStatus($data&#091;&#039;status&#039;])\n                -&gt;setUserId($data&#091;&#039;user_id&#039;]);\n            if (isset($data&#091;&#039;products&#039;])) {\n                $model-&gt;setProducts(implode(&#039;,&#039;, $data&#091;&#039;products&#039;]));\n            } else {\n                $model-&gt;setProducts(&#039;&#039;);\n            }\n            $model-&gt;save();\n            $this-&gt;messageManager-&gt;addSuccess(__(&#039;You have successfully created the blog.&#039;));\n        }\n        return $resultRedirect-&gt;setPath(&#039;*\/*\/&#039;);\n    }\n\n    \/**\n     * Check Autherization\n     *\n     * @return boolean\n     *\/\n    public function _isAllowed()\n    {\n        return $this-&gt;_authorization-&gt;isAllowed(&#039;Webkul_BlogManager::save&#039;);\n    }\n}<\/pre>\n\n\n\n<p>We have set the fields just like before. But there are minor changes for the <strong><strong>$data[&#8216;products&#8217;]<\/strong><\/strong> field to check whether the Related Products are set or not. <\/p>\n\n\n\n<p>Also, the <strong>$data[&#8216;products&#8217;]<\/strong> is a multi-select type field we have used the <strong>implode<\/strong> function to convert to string.<\/p>\n\n\n\n<p>We are done now. You should be able to save all the fields.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Repository<\/h2>\n\n\n\n<p>We have seen how we can use models to perform CRUD operations. Magento 2 has another thing called Repository to perform these operations. <\/p>\n\n\n\n<p>You can think of repositories as higher level implementation than the factories. Repositories have fixed methods like <strong>get<\/strong>, <strong>list<\/strong>,<strong> save<\/strong>,<strong> and delete<\/strong>.<\/p>\n\n\n\n<p>Magento recommends using the corresponding repositories instead of the model.<\/p>\n\n\n\n<p>Please go through this blog and also google &#8220;Repository in Magento 2&#8221; and &#8220;Difference between Repository and Factory in Magento 2&#8221; to get a better understanding.<\/p>\n\n\n\n<p><a href=\"https:\/\/webkul.com\/blog\/magento2-repository-design-pattern\/\" target=\"_blank\" rel=\"noreferrer noopener\"><strong>Magento2 Repository Design Pattern<\/strong><\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Recommended Exercises<\/h2>\n\n\n\n<p>Please implement these recommended exercises on the front-end. Try with the factory and repository to get a better idea about them.<\/p>\n\n\n\n<p>1. List orders of a customer given the email id.<\/p>\n\n\n\n<p>2. List items of an order given the order increment id.<\/p>\n\n\n\n<p>3. List products and quantity purchased by a customer given the customer name (assume customers have unique names).<\/p>\n\n\n\n<p>4. Implement product search functionality based on the product name and sku with the sort by price and pagination feature.<\/p>\n\n\n\n<p>5. Print the category tree structure.<\/p>\n\n\n\n<p><br>Next Blog -&gt; <a href=\"https:\/\/webkul.com\/blog\/magento-2-development-22-helper\/\">Magento 2 Development 25: Helper<\/a><\/p>\n\n\n\n<p>Previous Blog -&gt;&nbsp;<a href=\"https:\/\/webkul.com\/blog\/magento-2-development-20-add-button\/\" target=\"_blank\" rel=\"noreferrer noopener\">Magento 2 Development 23: Add Button<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>We&#8217;ve explored how to use custom table collections in Magento. Magento already has models and collections for things like customers, products, and orders. In this blog, we\u2019ll focus on using customer and product collections. At the end, I\u2019ll share some recommended exercises to help you deepen your understanding. These exercises are based on practices from <a href=\"https:\/\/webkul.com\/blog\/magento-2-development-21-loading-magentos-data\/\">[&#8230;]<\/a><\/p>\n","protected":false},"author":201,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9121],"tags":[2056,2460,2070],"class_list":["post-297489","post","type-post","status-publish","format-standard","hentry","category-magento-2","tag-magento","tag-magento-2","tag-magento2"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Magento 2 Development 24: Loading Magento&#039;s Data - Webkul Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/webkul.com\/blog\/magento-2-development-21-loading-magentos-data\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Magento 2 Development 24: Loading Magento&#039;s Data - Webkul Blog\" \/>\n<meta property=\"og:description\" content=\"We&#8217;ve explored how to use custom table collections in Magento. Magento already has models and collections for things like customers, products, and orders. In this blog, we\u2019ll focus on using customer and product collections. At the end, I\u2019ll share some recommended exercises to help you deepen your understanding. These exercises are based on practices from [...]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/webkul.com\/blog\/magento-2-development-21-loading-magentos-data\/\" \/>\n<meta property=\"og:site_name\" content=\"Webkul Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/webkul\/\" \/>\n<meta property=\"article:published_time\" content=\"2021-07-28T04:45:39+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-12T05:47:15+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/webkul.com\/blog\/wp-content\/uploads\/2021\/07\/2021-07-22_16-22-1200x526.png\" \/>\n<meta name=\"author\" content=\"Sanjay Chouhan\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@webkul\" \/>\n<meta name=\"twitter:site\" content=\"@webkul\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Sanjay Chouhan\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/webkul.com\/blog\/magento-2-development-21-loading-magentos-data\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/magento-2-development-21-loading-magentos-data\/\"},\"author\":{\"name\":\"Sanjay Chouhan\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/645580979f637b0e355deea21bd07462\"},\"headline\":\"Magento 2 Development 24: Loading Magento&#8217;s Data\",\"datePublished\":\"2021-07-28T04:45:39+00:00\",\"dateModified\":\"2024-11-12T05:47:15+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/webkul.com\/blog\/magento-2-development-21-loading-magentos-data\/\"},\"wordCount\":757,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/magento-2-development-21-loading-magentos-data\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/webkul.com\/blog\/wp-content\/uploads\/2021\/07\/2021-07-22_16-22-1200x526.png\",\"keywords\":[\"magento\",\"Magento 2\",\"Magento2\"],\"articleSection\":[\"Magento 2\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/webkul.com\/blog\/magento-2-development-21-loading-magentos-data\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/webkul.com\/blog\/magento-2-development-21-loading-magentos-data\/\",\"url\":\"https:\/\/webkul.com\/blog\/magento-2-development-21-loading-magentos-data\/\",\"name\":\"Magento 2 Development 24: Loading Magento's Data - Webkul Blog\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/webkul.com\/blog\/magento-2-development-21-loading-magentos-data\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/magento-2-development-21-loading-magentos-data\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/webkul.com\/blog\/wp-content\/uploads\/2021\/07\/2021-07-22_16-22-1200x526.png\",\"datePublished\":\"2021-07-28T04:45:39+00:00\",\"dateModified\":\"2024-11-12T05:47:15+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/webkul.com\/blog\/magento-2-development-21-loading-magentos-data\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/webkul.com\/blog\/magento-2-development-21-loading-magentos-data\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/magento-2-development-21-loading-magentos-data\/#primaryimage\",\"url\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/07\/2021-07-22_16-22.png\",\"contentUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/07\/2021-07-22_16-22.png\",\"width\":1799,\"height\":789,\"caption\":\"2021-07-22_16-22\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/webkul.com\/blog\/magento-2-development-21-loading-magentos-data\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/webkul.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Magento 2 Development 24: Loading Magento&#8217;s Data\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/webkul.com\/blog\/#website\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"name\":\"Webkul Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/webkul.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/webkul.com\/blog\/#organization\",\"name\":\"WebKul Software Private Limited\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"contentUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"width\":380,\"height\":380,\"caption\":\"WebKul Software Private Limited\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/webkul\/\",\"https:\/\/x.com\/webkul\",\"https:\/\/www.instagram.com\/webkul\/\",\"https:\/\/www.linkedin.com\/company\/webkul\",\"https:\/\/www.youtube.com\/user\/webkul\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/645580979f637b0e355deea21bd07462\",\"name\":\"Sanjay Chouhan\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/cd6ee19f99bd1fcafef819135529c952d7c875d06fedd9fd4c4eb0996bafc1bd?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/cd6ee19f99bd1fcafef819135529c952d7c875d06fedd9fd4c4eb0996bafc1bd?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g\",\"caption\":\"Sanjay Chouhan\"},\"sameAs\":[\"https:\/\/www.instagram.com\/sanjaychouhansc\/\",\"https:\/\/in.linkedin.com\/in\/scchouhansanjay\"],\"url\":\"https:\/\/webkul.com\/blog\/author\/sanjay-chouhan180\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Magento 2 Development 24: Loading Magento's Data - Webkul Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/webkul.com\/blog\/magento-2-development-21-loading-magentos-data\/","og_locale":"en_US","og_type":"article","og_title":"Magento 2 Development 24: Loading Magento's Data - Webkul Blog","og_description":"We&#8217;ve explored how to use custom table collections in Magento. Magento already has models and collections for things like customers, products, and orders. In this blog, we\u2019ll focus on using customer and product collections. At the end, I\u2019ll share some recommended exercises to help you deepen your understanding. These exercises are based on practices from [...]","og_url":"https:\/\/webkul.com\/blog\/magento-2-development-21-loading-magentos-data\/","og_site_name":"Webkul Blog","article_publisher":"https:\/\/www.facebook.com\/webkul\/","article_published_time":"2021-07-28T04:45:39+00:00","article_modified_time":"2024-11-12T05:47:15+00:00","og_image":[{"url":"https:\/\/webkul.com\/blog\/wp-content\/uploads\/2021\/07\/2021-07-22_16-22-1200x526.png","type":"","width":"","height":""}],"author":"Sanjay Chouhan","twitter_card":"summary_large_image","twitter_creator":"@webkul","twitter_site":"@webkul","twitter_misc":{"Written by":"Sanjay Chouhan","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/webkul.com\/blog\/magento-2-development-21-loading-magentos-data\/#article","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/magento-2-development-21-loading-magentos-data\/"},"author":{"name":"Sanjay Chouhan","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/645580979f637b0e355deea21bd07462"},"headline":"Magento 2 Development 24: Loading Magento&#8217;s Data","datePublished":"2021-07-28T04:45:39+00:00","dateModified":"2024-11-12T05:47:15+00:00","mainEntityOfPage":{"@id":"https:\/\/webkul.com\/blog\/magento-2-development-21-loading-magentos-data\/"},"wordCount":757,"commentCount":0,"publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"image":{"@id":"https:\/\/webkul.com\/blog\/magento-2-development-21-loading-magentos-data\/#primaryimage"},"thumbnailUrl":"https:\/\/webkul.com\/blog\/wp-content\/uploads\/2021\/07\/2021-07-22_16-22-1200x526.png","keywords":["magento","Magento 2","Magento2"],"articleSection":["Magento 2"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/webkul.com\/blog\/magento-2-development-21-loading-magentos-data\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/webkul.com\/blog\/magento-2-development-21-loading-magentos-data\/","url":"https:\/\/webkul.com\/blog\/magento-2-development-21-loading-magentos-data\/","name":"Magento 2 Development 24: Loading Magento's Data - Webkul Blog","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/webkul.com\/blog\/magento-2-development-21-loading-magentos-data\/#primaryimage"},"image":{"@id":"https:\/\/webkul.com\/blog\/magento-2-development-21-loading-magentos-data\/#primaryimage"},"thumbnailUrl":"https:\/\/webkul.com\/blog\/wp-content\/uploads\/2021\/07\/2021-07-22_16-22-1200x526.png","datePublished":"2021-07-28T04:45:39+00:00","dateModified":"2024-11-12T05:47:15+00:00","breadcrumb":{"@id":"https:\/\/webkul.com\/blog\/magento-2-development-21-loading-magentos-data\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/webkul.com\/blog\/magento-2-development-21-loading-magentos-data\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/magento-2-development-21-loading-magentos-data\/#primaryimage","url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/07\/2021-07-22_16-22.png","contentUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/07\/2021-07-22_16-22.png","width":1799,"height":789,"caption":"2021-07-22_16-22"},{"@type":"BreadcrumbList","@id":"https:\/\/webkul.com\/blog\/magento-2-development-21-loading-magentos-data\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/webkul.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Magento 2 Development 24: Loading Magento&#8217;s Data"}]},{"@type":"WebSite","@id":"https:\/\/webkul.com\/blog\/#website","url":"https:\/\/webkul.com\/blog\/","name":"Webkul Blog","description":"","publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/webkul.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/webkul.com\/blog\/#organization","name":"WebKul Software Private Limited","url":"https:\/\/webkul.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","contentUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","width":380,"height":380,"caption":"WebKul Software Private Limited"},"image":{"@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/webkul\/","https:\/\/x.com\/webkul","https:\/\/www.instagram.com\/webkul\/","https:\/\/www.linkedin.com\/company\/webkul","https:\/\/www.youtube.com\/user\/webkul\/"]},{"@type":"Person","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/645580979f637b0e355deea21bd07462","name":"Sanjay Chouhan","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/cd6ee19f99bd1fcafef819135529c952d7c875d06fedd9fd4c4eb0996bafc1bd?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/cd6ee19f99bd1fcafef819135529c952d7c875d06fedd9fd4c4eb0996bafc1bd?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g","caption":"Sanjay Chouhan"},"sameAs":["https:\/\/www.instagram.com\/sanjaychouhansc\/","https:\/\/in.linkedin.com\/in\/scchouhansanjay"],"url":"https:\/\/webkul.com\/blog\/author\/sanjay-chouhan180\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/297489","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/users\/201"}],"replies":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/comments?post=297489"}],"version-history":[{"count":12,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/297489\/revisions"}],"predecessor-version":[{"id":473547,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/297489\/revisions\/473547"}],"wp:attachment":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/media?parent=297489"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/categories?post=297489"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/tags?post=297489"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}