In my project I want to save multiple data in seperate database table rows.
In my Controller action the code is below:
$deletedProducts = new \app\models\ProductlinesDeleted();
$app = \app\models\Productlines::find()
->where(['product_id' => $id])->all();
foreach ($app as $prod){
$deletedProducts->productline_id = $prod->productline_id;
$deletedProducts->area_id = $prod->area_id;
$deletedProducts->product_id = $id;
$deletedProducts->internal_code = $prod->internal_code;
$deletedProducts->save();
$prod->delete();
}
return $this->redirect(['index']);
The $app can return multiple products. SO based on that i want to save the data in the database table.
- Every product has an area_id.
- Every product will have a single area_id.
For example i have
- Product 1 with area 1
- Product 1 with area 2
So there are 2 products with different areas. When I perform the action, It has to save:
- Product 1 with area 1 in the database table row.
Product 1 with area 2 in the database table next row.
How can i achieve this?? Thank you..