i have this code in my controller with create action ,user are entering multiple emails in textbox with comma separated ,i m exploding and saving then one by one but it is not saving in db only last record is not going
below is my code
public function actionCreate()
{
$model = new InviteInfo();
$this->performAjaxValidation($model);
if ($model->load(Yii::$app->request->post())) {
echo $emails=explode(',',$model->email);
for($i=0;$i<count($emails);$i++){
$model->email=$emails[$i]; //exit;
$model->created_at=date('Y-m-d h:i:s');
$model->save();
}
return $this->redirect(['index']);
} else {
return $this->render('create', [
'model' => $model,
]);
}
}
only second value is saving ,second loop is saving,first is not saving
what is wrong in this?