[ad_1]
I’m working on a reactJs and laravel project.
I’m on creating Chat I want to display the messages between the sender and the current user but I get juste the messages of the sender.
How can I can both sender and current user messages
I tried on creating a function on my server side but I get juste the sender messages.
this is the code
function getChats($id){
$types= chat::all()->where('userId', $id);
$c= DB::table('chats')->where('userId', $id)->get();
foreach ($c as $chats) {
$chats->chat = chat::select('senderId','message','time')->where('senderId', $chats->senderId)->get();
}
foreach ($types as $chats) {
$chats->chat = chat::select('senderId','message','time')->where('senderId', $chats->senderId)->get();
}
return ['chat' => $c, 'contact' => $types];
}
for eg: if I have a sender with id=3 when the current user with an id=2 respond him. the sender become the current user that’s mean the sender id become 2 and user_id become=3. It’s okey for the add I get data on database but the get method is missing something.
please any suggestions ? I would be very thankful if u help me. IT’s an EMERGENCY
[ad_2]