-
app/Http/Livewire/LikeReply.php
Open in GitHubuse App\Jobs\LikeReply as LikeReplyJob; use App\Jobs\UnlikeReply as UnlikeReplyJob; use App\Models\Reply; use Illuminate\Foundation\Bus\DispatchesJobs; use Illuminate\Support\Facades\Auth; use Livewire\Component; final class LikeReply extends Component { use DispatchesJobs; public $reply; public function mount(Reply $reply): void { $this->reply = $reply; } public function toggleLike(): void { if (Auth::guest()) { return; } if ($this->reply->isLikedBy(Auth::user())) { $this->dispatchNow(new UnlikeReplyJob($this->reply, Auth::user())); } else { $this->dispatchNow(new LikeReplyJob($this->reply, Auth::user())); } } }
-
resources/views/livewire/like-reply.blade.php
Open in GitHub<div class="thread-info-likes"> @if (Auth::guest()) <div class="text-gray-600 px-4 py-2 border-r inline-block"> <span class="text-2xl mr-1">?</span> {{ count($this->reply->likes()) }} </div> @else <button type="button" wire:click="toggleLike" class="text-lio-600 px-4 py-2 border-r"> <span class="text-2xl mr-1">?</span> {{ count($this->reply->likes()) }} </button> @endif </div>
-
resources/views/forum/threads/show.blade.php
Open in GitHub// <div class="border-t"> <livewire:like-reply :reply="$reply"/> </div> //