Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

ploi-deploy/roadmap

527 stars
3 code files
View ploi-deploy/roadmap on GitHub

app/Http/Livewire/Item/VoteButton.php

Open in GitHub
use App\Models\Item;
use App\Models\Vote;
use Livewire\Component;
 
class VoteButton extends Component
{
public Item $item;
public Vote|null $vote;
 
public function toggleUpvote()
{
$this->item->toggleUpvote();
$this->item = $this->item->refresh();
}
 
public function unsubscribe()
{
$this->vote->update(['subscribed' => false]);
 
$this->item = $this->item->refresh();
}
 
public function subscribe()
{
$this->vote->update(['subscribed' => true]);
 
$this->item = $this->item->refresh();
}
 
public function render()
{
$this->vote = $this->item->getUserVote();
 
return view('livewire.item.vote-button');
}
}

resources/views/livewire/item/vote-button.blade.php

Open in GitHub
<div class="flex items-center space-x-4 p-1">
<x-filament::button :color="$vote ? 'primary' : 'secondary'" wire:click="toggleUpvote">
@if($vote)
<x-heroicon-o-thumb-up class="w-5 h-5"/>
@else
<x-heroicon-o-thumb-up class="w-5 h-5"/>
@endif
</x-filament::button>
 
<span>{{ $item->total_votes }} total {{ trans_choice('messages.votes', $item->total_votes) }}</span>
 
@if($this->vote)
@if($this->vote->subscribed)
<button class="border-b border-dotted font-semibold border-gray-500" x-data x-tooltip.raw="Unsubscribe so you don't receive any notifications anymore about this item" wire:click="unsubscribe">
unsubscribe
</button>
@else
<button class="border-b border-dotted font-semibold border-gray-500" x-data x-tooltip.raw="Subscribe to receive notifications about updates on this item" wire:click="subscribe">
subscribe
</button>
@endif
@endif
 
</div>

resources/views/item.blade.php

Open in GitHub
//
<livewire:item.vote-button :item="$item"/>
//

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.