diff --git a/app/Livewire/Messages.php b/app/Livewire/Messages.php index 9597ebe..0add638 100644 --- a/app/Livewire/Messages.php +++ b/app/Livewire/Messages.php @@ -33,6 +33,8 @@ public function openChat($id): void { $this->selectedUser = User::find($id); $this->messages = $this->loggedInUser->messages()->where('receiver_id', $id)->orWhere('sender_id', $id)->orderBy('created_at', 'asc')->get(); + + $this->dispatch('chatOpened'); } //sendMessage diff --git a/app/Models/User.php b/app/Models/User.php index c9a3ae8..e734646 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -34,9 +34,9 @@ public function messages(): HasMany return $this->hasMany(Message::class, 'sender_id'); } - public function getLastMessageAttribute(): string + public function getLastMessageAttribute(): ?Message { - return $this->messages()->latest()->first()->message ?? ''; + return $this->messages()->orderBy('created_at', 'desc')->first(); } public function referrals(): HasMany diff --git a/resources/css/app.css b/resources/css/app.css index 43da3db..91b7ae8 100644 --- a/resources/css/app.css +++ b/resources/css/app.css @@ -45,11 +45,11 @@ input:-webkit-autofill { } .received-message{ - @apply rounded-t-2xl rounded-br-2xl bg-gray-200 text-gray-700 p-1 px-4; + @apply rounded-t-2xl rounded-br-2xl bg-green-400 overflow-hidden text-gray-700 p-1 px-4; } .received-message-attachment{ - @apply rounded-b-2xl overflow-clip rounded-tr-2xl bg-gray-200 text-gray-700 p-1 mt-1; + @apply rounded-b-2xl overflow-clip rounded-tr-2xl bg-green-400 text-gray-700 p-1; } .sent-message-attachment{ diff --git a/resources/views/livewire/display-chat-message.blade.php b/resources/views/livewire/display-chat-message.blade.php index 7f57127..8499a76 100644 --- a/resources/views/livewire/display-chat-message.blade.php +++ b/resources/views/livewire/display-chat-message.blade.php @@ -17,7 +17,7 @@ class="inline-block {{ $message->sender_id == Auth::id() ? 'bg-blue-500 text-whi
+ class="bg-gray-200 rounded-xl ring-1 ring-gray-100 overflow-hidden relative"> @if (in_array($attachment->type, ['image/jpeg', 'image/png', 'image/gif']))

No messages yet.

@else -
+
@foreach($messages as $message) - + @endforeach
@endif @@ -86,7 +86,7 @@ class="w-12 h-12 bg-white rounded-full">

- {{ $user->lastMessage ? $user->lastMessage->message : 'No message yet' }} + {{ $user->lastMessage ? $user->lastMessage->content : 'No message yet' }}

@@ -99,3 +99,16 @@ class="w-12 h-12 bg-white rounded-full"> +@script + +@endscript