app/Api/V1/Controllers/ChatController.php
/**
     * create a comment
     *
     * @param ChatGroupCreateRequest $request
     * @return Comment|\Illuminate\Http\JsonResponse
     */
create a comment
@param ChatGroupCreateRequest $request
@return Comment|\Illuminate\Http\JsonResponse
create a comment @param ChatGroupCreateRequest $request @return Comment| \ Illuminate \ Http \ JsonResponse
public function store(ChatGroupCreateRequest $request)
    {
        $authUser = $this->authUser();
        $users = (array)$request->participants;
        $users[] = $authUser->id;
        $users = array_unique($users);
        $existingUserArray = Arr::sort($users);
        $existingUserArrayString = implode(',', $existingUserArray);
        $hasExistingGroup = ChatGroup::query()->where('user_list', $existingUserArrayString)->first();
        if ($hasExistingGroup) {
            return $this->withMessage('Conversation already exists', 400);
        }
        $data = $request->only('description');
        $data['name'] = $request->group_name;
        $data['is_group'] = count($users) > 1;
        $data['created_by'] = $authUser->id;
        $data['user_list'] = $existingUserArrayString;
        $data['signature'] = $request->signature ? $request->signature : Str::orderedUuid();
        $group = ChatGroup::query()->create($data);
        foreach ($users as $participant) {
            $participantRecord = ChatGroupParticipant::query()->firstOrCreate(['chat_group_id' => $group->id, 'user_id' => $participant]);
        }
        $group->load('participants.internalUser', 'participants.vendor', 'creator');
        $obj = json_encode([
            'type' => 'group',
            'content' => $group
        ]);
        $redis = LRedis::connection();
        $redis->publish('message', $obj);
        return $this->withJson(['message' => 'Group created successfully', 'data' => $group]);
    }
public function store ( ChatGroupCreateRequest $ request ) { $ authUser = $ this -> authUser ( ) ; $ users = ( array ) $ request -> participants ; $ users [ ] = $ authUser -> id ; $ users = array_unique ( $ users ) ; $ existingUserArray = Arr :: sort ( $ users ) ; $ existingUserArrayString = implode ( ',' , $ existingUserArray ) ; $ hasExistingGroup = ChatGroup :: query ( ) -> where ( 'user_list' , $ existingUserArrayString ) -> first ( ) ; if ( $ hasExistingGroup ) { return $ this -> withMessage ( 'Conversation already exists' , 400 ) ; } $ data = $ request -> only ( 'description' ) ; $ data [ 'name' ] = $ request -> group_name ; $ data [ 'is_group' ] = count ( $ users ) > 1 ; $ data [ 'created_by' ] = $ authUser -> id ; $ data [ 'user_list' ] = $ existingUserArrayString ; $ data [ 'signature' ] = $ request -> signature ? $ request -> signature : Str :: orderedUuid ( ) ; $ group = ChatGroup :: query ( ) -> create ( $ data ) ; foreach ( $ users as $ participant ) { $ participantRecord = ChatGroupParticipant :: query ( ) -> firstOrCreate ( [ 'chat_group_id' => $ group -> id , 'user_id' => $ participant ] ) ; } $ group -> load ( 'participants.internalUser' , 'participants.vendor' , 'creator' ) ; $ obj = json_encode ( [ 'type' => 'group' , 'content' => $ group ] ) ; $ redis = LRedis :: connection ( ) ; $ redis -> publish ( 'message' , $ obj ) ; return $ this -> withJson ( [ 'message' => 'Group created successfully' , 'data' => $ group ] ) ; }
create a comment
 @param ChatGroupCreateRequest $request
 @return Comment|\Illuminate\Http\JsonResponse
create a comment @param ChatGroupCreateRequest $request @return Comment| \ Illuminate \ Http \ JsonResponse
//        remove duplicated participants from //            if ($participantRecord->wasRecentlyCreated) { ////            todo: notify participant for the created group //            } //        $event = (new ChatGroupEvent($group)); //        broadcast($event);