Skip to content

Commit

Permalink
Changed avatars to Dicebear API
Browse files Browse the repository at this point in the history
  • Loading branch information
Raccoon254 committed May 19, 2024
1 parent 78a333b commit dfd26aa
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 12 deletions.
15 changes: 9 additions & 6 deletions app/Livewire/Messages.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ public function mount(): void
}

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->selectedUser = User::find($id);
$this->messages = $this->loggedInUser->messages()->where('receiver_id', $id)->orWhere('sender_id', $id)->orderBy('created_at', 'asc')->get();
}

//sendMessage
public function sendMessage(): void
Expand All @@ -56,8 +56,11 @@ public function render(): View
return view('messages',
[
'clients' => User::where('role', 'client')
->where('name', 'like', '%' . $this->search . '%')->orWhere('email', 'like', '%' . $this->search . '%')
->get()
->where(function ($query) {
$query->where('name', 'like', '%' . $this->search . '%')
->orWhere('email', 'like', '%' . $this->search . '%');
})
->get()
]
);
}
Expand Down
16 changes: 15 additions & 1 deletion app/Livewire/SendMessageInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,25 @@

namespace App\Livewire;

use App\Models\User;
use Illuminate\View\View;
use Livewire\Component;
use Livewire\WithFileUploads;

class SendMessageInput extends Component
{
public function render()
use WithFileUploads;

public $message;
public array $attachments = [];
public User $recipient;

public function mount($selectedUser): void
{
$this->recipient = $selectedUser;
}

public function render(): View
{
return view('livewire.send-message-input');
}
Expand Down
5 changes: 4 additions & 1 deletion app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,12 @@ public function referrals(): HasMany
return $this->hasMany(Referral::class, 'referrer_id');
}

//https://api.dicebear.com/8.x/pixel-art/svg?seed={{md5($this->email)}}
// https://mighty.tools/mockmind-api/content/cartoon/' . $this->id. '.jpg

public function getAvatarAttribute(): string
{
return 'https://mighty.tools/mockmind-api/content/cartoon/' . $this->id. '.jpg';
return 'https://api.dicebear.com/8.x/avataaars/svg?seed=' . $this->name;
}

public function getProfilePhotoAttribute(): string
Expand Down
8 changes: 4 additions & 4 deletions resources/views/messages.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ class="w-12 h-12 rounded-full">
<div class="h-full flex flex-col overflow-y-auto">
@if ($messages->count() == 0)
<div class="flex items-center flex-col justify-center h-full">
<i class="fa-regular fa-bell-slash text-4xl text-gray-500"></i>
<i class="far fa-bell-slash text-4xl text-gray-500"></i>
<p class="text-gray-500">No messages yet.</p>
</div>
@else
<div class="p-6 space-y-4">
<div class="space-y-4">
@foreach($messages as $message)
<livewire:DisplayChatMessage :message="$message" :key="$message->id"/>
@endforeach
Expand All @@ -51,7 +51,7 @@ class="w-12 h-12 rounded-full">
<!-- Search -->
<div class="flex sticky flex-col rounded-lg">
<div class="flex relative gap-3 bg-gray-100 rounded-lg">
<input type="text" wire:model.live="search" placeholder="Type to search ..."
<input name="search" id="searchInput" type="text" wire:model.live="search" placeholder="Type to search ..."
class="w-full p-2 rounded-lg border border-gray-200 focus:outline-none">
<div
class="absolute text-black/80 right-5 top-[50%] transform translate-x-1/2 -translate-y-1/2">
Expand All @@ -67,7 +67,7 @@ class="absolute text-black/80 right-5 top-[50%] transform translate-x-1/2 -trans
wire:click="openChat({{ $user->id }})">
<div class="">
<img src="{{ $user->profile_photo }}" alt="{{ $user->name }}"
class="w-12 h-12 rounded-full">
class="w-12 h-12 bg-white rounded-full">
</div>
<div class="w-2/3">
<h1 class="text-gray-800 font-semibold">{{ $user->name }}</h1>
Expand Down

0 comments on commit dfd26aa

Please sign in to comment.