Вот мой запрос:
Код: Выделить всё
$data = [];
$chatusers = Chat::latest()->get(['reciver_id']);
$chatusers = collect($chatusers)->unique()->values()->all();
foreach ($chatusers as $user) {
if ($user['reciver_id'] >= 5000) {
$message = Chat::where('reciver_id', $user['reciver_id'])
->latest()
->first();
array_push($data, $message);
} else {
$message = Chat::where('sender_id', $user['reciver_id'])
->orWhere('reciver_id', $user['reciver_id'])
->latest()
->first();
array_push($data, $message);
}
}
https://i.sstatic.net/dKEKs.jpg
Вот экран для списка чатов:-
https://i.sstatic.net/6VAmH.jpg
Я не управляю отношениями.
Подробнее здесь: https://stackoverflow.com/questions/578 ... l-eloquent
Мобильная версия