Hello folks!
I’m not so good with Yii2 but I’m trying to learn it.
I want to change the status of a friendship from ‘0’ to ‘1’ when I push a button. Because I don’t know how to do that directly, I am trying to do this:
echo Html::a(' Accept friend', ['/users/friendadded', 'id'=>($model->id)], ['class'=>'btn btn-primary']);
and in friendadded.php I’m doing the following:
$friendPetition = Friendship::find()
->where(['friend_id'=>($model->id), 'status'=>0])
->all();
foreach ($friendPetition as $result) {
echo "Petition sent from: ";
$friendPetition1=$result->inviter_id;
echo $friendPetition1;
echo "Petition sent to: ";
$friendPetition2=$result->friend_id;
echo $friendPetition2;
$friendOn = Friendship::findOne($friendPetition1, $friendPetition2);
$friendOn->status = 1;
$friendOn->update();
}
The problem is that $friendPetition2 is ‘6’, but it updates the first one in my database, the friend_id = ‘5’.
If someone can help me…
Thank you very much!