+92-301-1000201 [email protected]
26 views

In the previous tutorial, you came to know how to create a table in Magento 2. This tutorial is all about creating a model file to perform CRUD operation.

To use a table in Magento, one has to create files for the model.

Bookmark this tutorial while developing a Magento 2 module.

Steps to Create Model File to Perform CRUD Operation in Magento 2:

Create a file having a name Extension.php in given address: app\code\Meetanshi\Extension\Model

The name of the table is Extension here so we have given the name of a file Extension.php.

For fetching and loading the data, you need to create another file “Extension.php” on a given location.

Create file app\code\Meetanshi\Extension\Model\ResourceModel\Extension.php

Another important file is Collection.php

Collection.php file helps to collect all the data of the table.

In the given path, create a file and copy the code.

app\code\Extension\Model\ResourceModel\Extension\Collection.php

Done!

I would be happy to answer your questions regarding this blog.

Please do consider sharing this blog with interested ones via social media.

Thanks a bunch.