I have a variable
I have run foreach loop for every item
$tags = ['#first_Tag','#second_tag','#third_tag','#fourth_Tag'];
foreach ($tags as $t) :
$model = new Tags;
$model->tag_name = $t;
$model->save(); //yii2
endforeach;
this function only saves the last item which is #fourth_Tag. Can any one have solution about this. Thanks in advance.
Try this..
$tags = ['#first_Tag','#second_tag','#third_tag','#fourth_Tag'];
$model = new Tags;
foreach ($tags as $t) :
$model->id = NULL; //primary key(auto increment id) id
$model->isNewRecord = true;
$model->tag_name = $t;
$model->save(); //yii2
endforeach;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With