public function actionSendmessage()
 {
     //insert into conversation first and get the PK
     //then insert into rooms_conversations by adding the conversation's PK
     $model = new Conversations();
     if ($model->load(\Yii::$app->getRequest()->getBodyParams(), '')) {
         $chatData = \Yii::$app->getRequest()->getBodyParams();
         $model->user_id = $chatData['user_id'];
         $model->message = $chatData['message'];
         if ($model->save()) {
             $cr_id = $model->cr_id;
             $room = new RoomsConversations();
             $room->mr_id = $chatData['mr_id'];
             $room->cr_id = $cr_id;
             return $room->save();
         }
     }
 }
Beispiel #2
0
 public function getAllconversations()
 {
     return $this->hasMany(Conversations::className(), ['cr_id' => 'mr_id'])->viaTable('rooms_conversations', ['rc_id' => 'mr_id']);
 }
 public function getAllConversations()
 {
     return $this->hasMany(Conversations::className(), ['cr_id' => 'rc_id']);
     //->viaTable('user', ['id' => 'user_id']);
 }