/** * Creates a new Mailbox model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Mailbox(['status' => 1]); if ($model->load(Yii::$app->request->post())) { $model->sender = Yii::$app->user->id; $receivers = $model->receiver; if (count($receivers) > 1) { $receivers = $model->receiver; foreach ($receivers as $receiver) { $model2 = new Mailbox(); $model2->attributes = $model->attributes; $model2->receiver = $receiver; $model2->save(); } } else { if ($model->save()) { } } return $this->redirect(['index']); } else { return $this->render('create', ['model' => $model]); } }