public function createConversation($users_ids) { if (count($users_ids) > 1) { //create new conv $conv = new ConversationEloquent(); $conv->save(); //get the id of conv, and add foreach user a line in conv_users foreach ($users_ids as $user_id) { $this->addConvUserRow($conv->id, $user_id); } $eventData = ['usersIds' => $users_ids, 'convId' => $conv->id]; return $eventData; } else { throw new NotEnoughUsersInConvException(); } }
/** * @param array $users_ids * @throws Exceptions\NotEnoughUsersInConvException * @return ConversationEloquent */ public function createConversation($users_ids) { if (count($users_ids) > 1) { //create new conv $conv = new ConversationEloquent(); $conv->save(); //get the id of conv, and add foreach user a line in conv_users foreach ($users_ids as $user_id) { $conv_user = new ConversationUsers(); $conv_user->conv_id = $conv->id; $conv_user->user_id = $user_id; try { $conv_user->save(); } catch (\Exception $ex) { } } $eventData = ['usersIds' => $users_ids, 'convId' => $conv->id]; $this->dispatcher->fire('conversation.created', [$eventData]); return $conv; } else { throw new NotEnoughUsersInConvException(); } }