{"id":283135,"date":"2021-02-16T15:22:20","date_gmt":"2021-02-16T15:22:20","guid":{"rendered":"https:\/\/webkul.com\/blog\/?p=283135"},"modified":"2025-05-28T10:24:54","modified_gmt":"2025-05-28T10:24:54","slug":"delete-operation-magento2","status":"publish","type":"post","link":"https:\/\/webkul.com\/blog\/delete-operation-magento2\/","title":{"rendered":"Delete operation in Magento 2"},"content":{"rendered":"\n<p>Let&#8217;s give our blog writer an option for deleting his\/her blog. After this, we will have completed the CRUD operations.<\/p>\n\n\n\n<p>Just like before we need to edit the <em>view\/frontend\/templates\/list.phtml<\/em><\/p>\n\n\n\n<p>Updated code for <em>view\/frontend\/templates\/list.phtml<\/em> file<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">&lt;table&gt;\n    &lt;tr&gt;\n        &lt;th&gt;\n            &lt;?= __(&quot;Id&quot;)?&gt;\n        &lt;\/th&gt;\n        &lt;th&gt;\n            &lt;?= __(&quot;Title&quot;)?&gt;\n        &lt;\/th&gt;\n        &lt;th&gt;\n            &lt;?= __(&quot;Content&quot;)?&gt;\n        &lt;\/th&gt;\n        &lt;th&gt;\n            &lt;?= __(&quot;Edit&quot;)?&gt;\n        &lt;\/th&gt;\n        &lt;th&gt;\n            &lt;?= __(&quot;Delete&quot;)?&gt;\n        &lt;\/th&gt;\n    &lt;\/tr&gt;\n    &lt;?php\n    $blogs = $block-&gt;getBlogs();\n\n    foreach ($blogs as $blog) {?&gt;\n    &lt;tr&gt;\n        &lt;td&gt;\n            &lt;?= $escaper-&gt;escapeHtml($blog-&gt;getId())?&gt;\n        &lt;\/td&gt;\n        &lt;td&gt;\n            &lt;?= $escaper-&gt;escapeHtml($blog-&gt;getTitle())?&gt;\n        &lt;\/td&gt;\n        &lt;td&gt;\n            &lt;?= substr($escaper-&gt;escapeHtml($blog-&gt;getContent()), 0, 20).&#039;...&#039;?&gt;\n        &lt;\/td&gt;\n        &lt;td&gt;\n            &lt;a href=&quot;&lt;?= $escaper-&gt;escapeUrl($block-&gt;getUrl(&#039;blog\/manage\/edit&#039;, &#091;&#039;id&#039;=&gt;$escaper-&gt;escapeHtml($blog-&gt;getId())]))?&gt;&quot;&gt;\n                &lt;?= __(&#039;Edit&#039;) ?&gt;\n            &lt;\/a&gt;\n        &lt;\/td&gt;\n        &lt;td&gt;\n            &lt;a href=&quot;&lt;?= $escaper-&gt;escapeUrl($block-&gt;getUrl(&#039;blog\/manage\/delete&#039;, &#091;&#039;id&#039;=&gt;$escaper-&gt;escapeHtml($blog-&gt;getId())]))?&gt;&quot;\n                onclick=&quot;return confirm(&#039;Are you sure you want to delete this blog?&#039;);&quot;&gt;\n                &lt;?= __(&#039;Delete&#039;) ?&gt;\n            &lt;\/a&gt;\n        &lt;\/td&gt;\n    &lt;\/tr&gt;\n    &lt;?php } ?&gt;\n&lt;\/table&gt;<\/pre>\n\n\n\n<p>Here we have added another column &#8220;Delete&#8221; and in the delete link we have used javascript&#8217;s confirm dialog. <\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1200\" height=\"556\" src=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/02\/2021-02-16_20-46-1200x556.png\" alt=\"2021-02-16_20-46\" class=\"wp-image-283147\" srcset=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/02\/2021-02-16_20-46-1200x556.png 1200w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/02\/2021-02-16_20-46-300x139.png 300w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/02\/2021-02-16_20-46-250x116.png 250w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/02\/2021-02-16_20-46-768x356.png 768w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/02\/2021-02-16_20-46-1536x712.png 1536w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/02\/2021-02-16_20-46.png 1693w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" loading=\"lazy\" \/><\/figure>\n\n\n\n<p>We will redirect the user to the list page after deleting the blog. So we just need to create the controller file. Please check the readymade <a href=\"https:\/\/store.webkul.com\/magento2-blog-extension.html\">Magento 2 Blog Extension<\/a> <\/p>\n\n\n\n<p>Let&#8217;s create <em>Controller\/Manage\/Delete.php<\/em> file,<\/p>\n\n\n\n<p>Code for <em>Controller\/Manage\/Delete.php<\/em> file<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">&lt;?php\nnamespace Webkul\\BlogManager\\Controller\\Manage;\n\nuse Magento\\Customer\\Controller\\AbstractAccount;\nuse Magento\\Framework\\App\\Action\\Context;\nuse Magento\\Customer\\Model\\Session;\n\nclass Delete extends AbstractAccount\n{\n    \/**\n     * @var \\Webkul\\BlogManager\\Model\\BlogFactory\n     *\/\n    protected $blogFactory;\n\n    \/**\n     * @var Magento\\Customer\\Model\\Session\n     *\/\n    protected $customerSession;\n\n    \/**\n     * @var \\Magento\\Framework\\Message\\ManagerInterface\n     *\/\n    protected $messageManager;\n\n    \/**\n     * Dependency Initilization\n     *\n     * @param Context $context\n     * @param \\Webkul\\BlogManager\\Model\\BlogFactory $blogFactory\n     * @param Session $customerSession\n     * @param \\Magento\\Framework\\Message\\ManagerInterface $messageManager\n     *\/\n    public function __construct(\n        Context $context,\n        \\Webkul\\BlogManager\\Model\\BlogFactory $blogFactory,\n        Session $customerSession,\n        \\Magento\\Framework\\Message\\ManagerInterface $messageManager\n    ) {\n        $this-&gt;blogFactory = $blogFactory;\n        $this-&gt;customerSession = $customerSession;\n        $this-&gt;messageManager = $messageManager;\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        $blogId = $this-&gt;getRequest()-&gt;getParam(&#039;id&#039;);\n        $customerId = $this-&gt;customerSession-&gt;getCustomerId();\n        $isAuthorised = $this-&gt;blogFactory-&gt;create()\n                                    -&gt;getCollection()\n                                    -&gt;addFieldToFilter(&#039;user_id&#039;, $customerId)\n                                    -&gt;addFieldToFilter(&#039;entity_id&#039;, $blogId)\n                                    -&gt;getSize();\n        if (!$isAuthorised) {\n            $this-&gt;messageManager-&gt;addError(__(&#039;You are not authorised to delete this blog.&#039;));\n            return $this-&gt;resultRedirectFactory-&gt;create()-&gt;setPath(&#039;blog\/manage&#039;);\n        } else {\n            $model = $this-&gt;blogFactory-&gt;create()-&gt;load($blogId);\n            $model-&gt;delete();\n            $this-&gt;messageManager-&gt;addSuccess(__(&#039;You have successfully deleted the blog.&#039;));\n        }     \n        return $this-&gt;resultRedirectFactory-&gt;create()-&gt;setPath(&#039;blog\/manage&#039;);\n    }\n}<\/pre>\n\n\n\n<p>There is nothing much to talk about here because we have seen very similar codes before also. The only thing you have to notice is the <strong><strong>$model-&gt;delete()<\/strong><\/strong> method. <\/p>\n\n\n\n<p>After loading the model we have deleted it with the <strong>delete()<\/strong> method and we have redirected to the list page.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1200\" height=\"596\" src=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/02\/2021-02-16_20-47-1200x596.png\" alt=\"2021-02-16_20-47\" class=\"wp-image-283148\" srcset=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/02\/2021-02-16_20-47-1200x596.png 1200w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/02\/2021-02-16_20-47-300x149.png 300w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/02\/2021-02-16_20-47-250x124.png 250w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/02\/2021-02-16_20-47-768x381.png 768w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/02\/2021-02-16_20-47-1536x763.png 1536w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/02\/2021-02-16_20-47.png 1680w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" loading=\"lazy\" \/><\/figure>\n\n\n\n<p>The folder structure till now,<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1200\" height=\"593\" src=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/07\/Selection_114-1200x593.png\" alt=\"Selection_114\" class=\"wp-image-390882\" srcset=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/07\/Selection_114-1200x593.png 1200w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/07\/Selection_114-300x148.png 300w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/07\/Selection_114-250x124.png 250w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/07\/Selection_114-768x380.png 768w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/07\/Selection_114.png 1499w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" loading=\"lazy\" \/><figcaption class=\"wp-element-caption\">Folder Structure<\/figcaption><\/figure>\n\n\n\n<p>Next Blog -&gt; <a href=\"https:\/\/webkul.com\/blog\/use-of-css-and-js-in-magento-2\/\">Magento 2 Development 14: CSS and JS<\/a><\/p>\n\n\n\n<p>Previous Blog -&gt; <a href=\"https:\/\/webkul.com\/blog\/magento-development-09-editing-and-updating\/\" target=\"_blank\" rel=\"noreferrer noopener\">Magento 2 Development 12: Editing and Updating<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Let&#8217;s give our blog writer an option for deleting his\/her blog. After this, we will have completed the CRUD operations. Just like before we need to edit the view\/frontend\/templates\/list.phtml Updated code for view\/frontend\/templates\/list.phtml file Here we have added another column &#8220;Delete&#8221; and in the delete link we have used javascript&#8217;s confirm dialog. We will redirect <a href=\"https:\/\/webkul.com\/blog\/delete-operation-magento2\/\">[&#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":[2460],"class_list":["post-283135","post","type-post","status-publish","format-standard","hentry","category-magento-2","tag-magento-2"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Delete operation in Magento 2 - Webkul Blog<\/title>\n<meta name=\"description\" content=\"Learn how to perform a delete operation in Magento 2 using best practices. Explore methods for deleting data programmatically using models.\" \/>\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\/delete-operation-magento2\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Delete operation in Magento 2 - Webkul Blog\" \/>\n<meta property=\"og:description\" content=\"Learn how to perform a delete operation in Magento 2 using best practices. Explore methods for deleting data programmatically using models.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/webkul.com\/blog\/delete-operation-magento2\/\" \/>\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-02-16T15:22:20+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-05-28T10:24:54+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/webkul.com\/blog\/wp-content\/uploads\/2021\/02\/2021-02-16_20-46-1200x556.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=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/webkul.com\/blog\/delete-operation-magento2\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/delete-operation-magento2\/\"},\"author\":{\"name\":\"Sanjay Chouhan\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/645580979f637b0e355deea21bd07462\"},\"headline\":\"Delete operation in Magento 2\",\"datePublished\":\"2021-02-16T15:22:20+00:00\",\"dateModified\":\"2025-05-28T10:24:54+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/webkul.com\/blog\/delete-operation-magento2\/\"},\"wordCount\":183,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/delete-operation-magento2\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/webkul.com\/blog\/wp-content\/uploads\/2021\/02\/2021-02-16_20-46-1200x556.png\",\"keywords\":[\"Magento 2\"],\"articleSection\":[\"Magento 2\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/webkul.com\/blog\/delete-operation-magento2\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/webkul.com\/blog\/delete-operation-magento2\/\",\"url\":\"https:\/\/webkul.com\/blog\/delete-operation-magento2\/\",\"name\":\"Delete operation in Magento 2 - Webkul Blog\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/webkul.com\/blog\/delete-operation-magento2\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/delete-operation-magento2\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/webkul.com\/blog\/wp-content\/uploads\/2021\/02\/2021-02-16_20-46-1200x556.png\",\"datePublished\":\"2021-02-16T15:22:20+00:00\",\"dateModified\":\"2025-05-28T10:24:54+00:00\",\"description\":\"Learn how to perform a delete operation in Magento 2 using best practices. Explore methods for deleting data programmatically using models.\",\"breadcrumb\":{\"@id\":\"https:\/\/webkul.com\/blog\/delete-operation-magento2\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/webkul.com\/blog\/delete-operation-magento2\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/delete-operation-magento2\/#primaryimage\",\"url\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/02\/2021-02-16_20-46.png\",\"contentUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/02\/2021-02-16_20-46.png\",\"width\":1693,\"height\":785,\"caption\":\"2021-02-16_20-46\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/webkul.com\/blog\/delete-operation-magento2\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/webkul.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Delete operation in Magento 2\"}]},{\"@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":"Delete operation in Magento 2 - Webkul Blog","description":"Learn how to perform a delete operation in Magento 2 using best practices. Explore methods for deleting data programmatically using models.","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\/delete-operation-magento2\/","og_locale":"en_US","og_type":"article","og_title":"Delete operation in Magento 2 - Webkul Blog","og_description":"Learn how to perform a delete operation in Magento 2 using best practices. Explore methods for deleting data programmatically using models.","og_url":"https:\/\/webkul.com\/blog\/delete-operation-magento2\/","og_site_name":"Webkul Blog","article_publisher":"https:\/\/www.facebook.com\/webkul\/","article_published_time":"2021-02-16T15:22:20+00:00","article_modified_time":"2025-05-28T10:24:54+00:00","og_image":[{"url":"https:\/\/webkul.com\/blog\/wp-content\/uploads\/2021\/02\/2021-02-16_20-46-1200x556.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":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/webkul.com\/blog\/delete-operation-magento2\/#article","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/delete-operation-magento2\/"},"author":{"name":"Sanjay Chouhan","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/645580979f637b0e355deea21bd07462"},"headline":"Delete operation in Magento 2","datePublished":"2021-02-16T15:22:20+00:00","dateModified":"2025-05-28T10:24:54+00:00","mainEntityOfPage":{"@id":"https:\/\/webkul.com\/blog\/delete-operation-magento2\/"},"wordCount":183,"commentCount":0,"publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"image":{"@id":"https:\/\/webkul.com\/blog\/delete-operation-magento2\/#primaryimage"},"thumbnailUrl":"https:\/\/webkul.com\/blog\/wp-content\/uploads\/2021\/02\/2021-02-16_20-46-1200x556.png","keywords":["Magento 2"],"articleSection":["Magento 2"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/webkul.com\/blog\/delete-operation-magento2\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/webkul.com\/blog\/delete-operation-magento2\/","url":"https:\/\/webkul.com\/blog\/delete-operation-magento2\/","name":"Delete operation in Magento 2 - Webkul Blog","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/webkul.com\/blog\/delete-operation-magento2\/#primaryimage"},"image":{"@id":"https:\/\/webkul.com\/blog\/delete-operation-magento2\/#primaryimage"},"thumbnailUrl":"https:\/\/webkul.com\/blog\/wp-content\/uploads\/2021\/02\/2021-02-16_20-46-1200x556.png","datePublished":"2021-02-16T15:22:20+00:00","dateModified":"2025-05-28T10:24:54+00:00","description":"Learn how to perform a delete operation in Magento 2 using best practices. Explore methods for deleting data programmatically using models.","breadcrumb":{"@id":"https:\/\/webkul.com\/blog\/delete-operation-magento2\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/webkul.com\/blog\/delete-operation-magento2\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/delete-operation-magento2\/#primaryimage","url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/02\/2021-02-16_20-46.png","contentUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/02\/2021-02-16_20-46.png","width":1693,"height":785,"caption":"2021-02-16_20-46"},{"@type":"BreadcrumbList","@id":"https:\/\/webkul.com\/blog\/delete-operation-magento2\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/webkul.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Delete operation in Magento 2"}]},{"@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\/283135","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=283135"}],"version-history":[{"count":11,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/283135\/revisions"}],"predecessor-version":[{"id":493906,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/283135\/revisions\/493906"}],"wp:attachment":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/media?parent=283135"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/categories?post=283135"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/tags?post=283135"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}