Updating fields in a database after each create triggered by the controller

So I am working on my first Yii project and is having some problems with a functionality I want to implement. Say for example I have a table for items and a table for delivery. Each time a delivery of a specific item is made I want that to update the current quantity of the item present in the database.

this is my create method in the delivery controller. Currently it is set to enter multiple deliveries at once. In here I want to update the item that corresponds to the delivery by adding the quantity to the item that has the same name as the item in the delivery. How would I accomplish this?

public function actionCreate()

{


	$model= array(new Delivery);


	// Uncomment the following line if AJAX validation is needed


	// $this->performAjaxValidation($model);





			if (isset($_POST['Delivery'])){


            $model = array();


            foreach ($_POST['Delivery'] as $key => $value) {


                $delivery = new Delivery();


                $delivery->attributes = $value;


                $model[] = $delivery;


            }


        }


        


        foreach ($model as $delivery) {


            $valid = $delivery->validate();


        }





        if ($valid) {


            try {


                foreach ($model as $delivery) {


                    $delivery->save();


                }


            } catch (Exception $e) {


                


            }





            $this->redirect(array('/site/page', 'view'=>'done'));


        }


    


    $this->render('create', array(


        'model' => $model


    ));


}