Magento 2 – How to Create CRUD Operations with Admin Grid

crudgridmagento2

How to create the CRUD operations with Admin Grid in Magento 2?

I want to :

  1. First of create frontend input form.
  2. frontend input form data get in admin grid.
  3. In admin grid Create delete options.
  4. In admin Grid Create edit (UPDATE) options.

How to achieve this. Please give the best way and the solution.

Thanks.

Best Answer

Create the CRUD operations with Admin Grid in Magento 2

Step-1 : Choose your Module Name like VendoreName and ModuleName

Step-2 : Create a folder like this /app/code/VendoreName/ModuleName

Step-3 : First create registration.php at app/code/VendoreName/ModuleName

Step-4 : Create module.xml at app/code/VendoreName/ModuleName/etc

Step-5 : Choose admin route name and create in routes.xml at app/code/VendoreName/ModuleName/etc/adminhtml

Step-6 : Create on table structure add into InstallSchema.php at app/code/VendoreName/ModuleName/Setup

Step-7 : Create Model files for access your table for DML operation.

Step-8 : Choose admin Conroller name(Index) and create folder like this app/code/VendoreName/ModuleName/Controller/Adminhtml/Index

Step-9 : Create your admin Action file for create admin pages At app/code/VendoreName/ModuleName/Controller/Adminhtml/Index for show grid and manupulate data in admingrid.(Index.php,Add.php,Delete.php,Edit.php,MassDelete.php,MassStatus.php,Save.php)

Step-10: But right now our module is not show. Now Create one menu and add this menu into magento menu list. craete menu.xml at app/code/VendoreName/ModuleName/etc/adminhtml (Menu action must assige carefull like AdminRouteName/AdminControllerName/AtcionFileName)

Step-11: Now we have to create layout at app/code/VendoreName/ModuleName/view/adminhtml/layout (file name must be like this adminroutname_admincontollername_actionfilename.xml all latters are small case and same as you define in file.)

Step-12: You can create grid using Block and Ui-component follow this click here

Step-13: Now admin part is over So create frontend route name routes.xml at app/code/VendoreName/ModuleName/etc/frontend

Step-14: Create Frontend Contoller Name Folder like (Index) like app/code/VendoreName/ModuleName/Controller/Index

Step-15: create action in it as you required. (Index.php,Add.php,Delete.php,Edit.php,MassDelete.php,MassStatus.php,Save.php)

Step-16: create layout for it. layout name must be like this frontendroutename_frontendcontrollername_frontendactionfilename.xml

Step-17: in layout file you call Block and phtml files for show content. click here for more

Step-18: Now your module is ready to use

Please check this all files are created and running well click here to show

Note: you can also use some step before and after as you comfort. but some step are required like route create, layout create etc

I Hope This Helps You