如何在yii2中为sql表的现有值添加值?

I have created a stock module in yii2. Using gii functionality I can add products to table. But what to do when product already exists in the table and new quantity needs to be added to existing quantity leaving total quantity in db. For example,

Products

Quantity

5

I need to update Quantity by any value for example '5+3', leaving other fields of sql table unchanged.

need output like below

Quantity

8

How do I update my controller to do that? And of course I want to be able to do it in create action.

Here are the steps you should follow:

  1. Figure out how you identify if a product already exists. Based on what? name? internal code? etc.
  2. When you create a product search the db to see if that product already exists based on your criteria.
  3. Decide what you do with the extra data, what if the product is already there based on the code but the name has changed.
  4. If it does exist then update the quantity.