CRUD Operation in one minute


Before we learn how to implement CRUD operation, let's first understand what is CRUD.

CRUD stands for Create, Read, Update & Delete.

Create means insert record into table, read, update and delete functions as name suggests. In REST API, we can have various services which should function as mentioned above and these operations are differentiated based on its HTTP methods.

POST for Create, GET for read, PUT for update and DELETE for delete. To implement CRUD operation in REST API we should create first below REST APIs

Without Prototype

You can skip this section if you already know CRUD. We will take example item which should be managed as per CRUD operation.

  1. GET item
  2. POST item
  3. PUT item
  4. DELETE item

Then we need to create table in database which will store item detail and then create an entity which will be mapped to this table. Once that is done we need to create queries to achieve those operations, these queries should be wrapped in method so that it can be called from controller.

If you have to implement above operation it may take around 30 minutes for experienced developer and may take longer time for other developers

Using console command

In nishchay to implement CRUD operation it won't take much time. Let's see how we can implement.

  1. Open terminal/Command prompt then change directory to application root directory

Now execute below command

php nishchay prototype -generate -new  

Once you execute above command, it will ask for Entity name. Then it will ask for properties which needs to be created.

Once entity is created it will asks whether you create table in database. You can discard this by typing N.

After entity has been, it will asks for controller path name.

That's it!!! All done

Console command will create controller with all CRUD related routes, it will also creates form to validate request for Update and insert operation.

Existing table

If you have an existing table in database you can also create CRUD operation using that table. To do this use below command:

php nishchay prototype -generate -table {name}
Learn more

Read prototype and console command to learn more.