@extends('layouts.simple.master') @section('title', 'Default') @section('css') @endsection @section('style') @endsection @section('breadcrumb-title')

Chat

@endsection @section('breadcrumb-items') @endsection @if (strtolower(Request::segment(1)) === 'client') @else @endif @section('content')
@if (strtolower(Request::segment(1)) !== 'client')
image)) src="{{ asset('public/storage/uploads/'.$admin_active_status->image) }}" @else src="{{ asset('assets/dummy_person.jpg') }}" @endif alt="">
Admin
    @if (!empty($users)) @php // Sort the chats by created_at or updated_at timestamp in descending order $latestChat = $chats->sortByDesc('created_at')->first(); $latestUser = null; $displayedUsers = []; // Find the user related to the latest chat if ($latestChat) { $latestUser = $users->firstWhere('id', $latestChat->sender_id) ?: $users->firstWhere('id', $latestChat->receiver_id); } @endphp @if ($latestUser) @php // Add the latest user to the displayedUsers array to avoid duplication later $displayedUsers[] = $latestUser->id; @endphp
  • image)) src="{{ asset('public/storage/uploads/'.$latestUser->image) }}" @else src="{{ asset('assets/dummy_person.jpg') }}" @endif alt="">
    {{ $latestUser->fname ." ". $latestUser->lname }}
    @php $words = explode(' ', $latestChat->message); $shortMessage = count($words) > 3 ? implode(' ', array_slice($words, 0, 3)) . '...' : $latestChat->message; @endphp @if (empty($shortMessage) && !empty($latestChat->attachment)) Sent an attachment...! @else {{$shortMessage}} @endif
  • @endif @foreach ($users as $user) @if (!in_array($user->id, $displayedUsers))
  • image)) src="{{ asset('public/storage/uploads/'.$user->image) }}" @else src="{{ asset('assets/dummy_person.jpg') }}" @endif alt="">
    {{ $user->fname ." ". $user->lname }}
    @php $userChat = $chats->first(function($chat) use ($user) { return $chat->sender_id == $user->id || $chat->receiver_id == $user->id; }); $words = $userChat ? explode(' ', $userChat->message) : []; $shortMessage = count($words) > 3 ? implode(' ', array_slice($words, 0, 3)) . '...' : ($userChat ? $userChat->message : ''); @endphp @if (empty($shortMessage) && !empty($userChat->attachment)) Sent an attachment...! @else {{$shortMessage}} @endif
  • @endif @endforeach @endif
@endif
@endsection @section('script') @endsection