2022-06-28

How to display data order by time not in the same bloc with laravel?

I'm working on reactJs and Laravel chat. Actually the problem is that when I try to display data for specifc two users (sender and reciever) I got them bloc by bloc not message by message . I got a bloc of messages for the sender and then a bloc of messages for the reciever this is the code :


  function getChats($id){
    $c= chat::all()->where('id', $id);

    //$types= chat::all()->where('id', $id);
 
    foreach ($c as $q) {
        $q=chat::where('senderId', $q->userId)
        ->where('userId', $q->senderId)->get();  
        foreach ($q as $a) {
        $a=chat::where('userId', $a->senderId)
        ->where('senderId', $a->userId)->get();  
            
         $finalResult = $a->merge($q);
    
        
         // return ['chat' => $s];
        }
    }
  
    
  
     
  
  return ['chat' => $finalResult];

  }

I merge the two queries to get the mssges of the sender (senderId) and the reciever(userId) thanks in advance for you help



No comments:

Post a Comment