/** * Deletes an existing Meal model. * If deletion is successful, the browser will be redirected to the 'index' page. * @param string $id * @return mixed */ public function actionDelete($id) { if ($this->findModel($id)->delete()) { $productImages = MealImage::findOne(['meal_id' => $id]); if (!empty($productImages)) { $image = Yii::$app->params['uploadPath'] . $productImages->image_new_url; if (unlink($image)) { $productImages->delete(); } } $mealItemManage = MealItemsManage::findOne(['meal_id' => $id]); if (!empty($mealItemManage)) { if (MealItemsManage::deleteAll(['meal_id' => $id])) { } } } return $this->redirect(['index']); }