forked from eatvio/eatvio-infra
eating plan added
This commit is contained in:
69
app/Http/Livewire/Plan/Comment/Upvote.php
Normal file
69
app/Http/Livewire/Plan/Comment/Upvote.php
Normal file
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire\Plan\Comment;
|
||||
|
||||
use Livewire\Component;
|
||||
use App\Models\PlanComment;
|
||||
|
||||
class Upvote extends Component
|
||||
{
|
||||
public PlanComment $comment;
|
||||
|
||||
public function mount(PlanComment $comment)
|
||||
{
|
||||
$this->comment = $comment;
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function render()
|
||||
{
|
||||
$upvotes = $this->comment->upvotes()->forPlanCommentsUpVote($this->comment)->count();
|
||||
$downvotes = $this->comment->upvotes()->forPlanCommentsDownVote($this->comment)->count();
|
||||
$sum = $upvotes - $downvotes;
|
||||
return view(
|
||||
'livewire.plan.comment.upvote',
|
||||
[
|
||||
'sum' => $sum,
|
||||
'isUpVoted' => $this->comment->isUpVoted(),
|
||||
'isDownVoted' => $this->comment->isDownVoted()
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
public function upvote()
|
||||
{
|
||||
if ($this->comment->isUpVoted()) {
|
||||
$this->comment->removeUpVote();
|
||||
return ;
|
||||
}
|
||||
|
||||
if ($this->comment->isDownVoted()) {
|
||||
$this->comment->removeDownVote();
|
||||
}
|
||||
|
||||
$this->comment->upvotes()->create([
|
||||
'user_id' => auth()->id(),
|
||||
'comment_id' => $this->comment->id,
|
||||
'type' => 'upvote'
|
||||
]);
|
||||
}
|
||||
|
||||
public function downvote()
|
||||
{
|
||||
if ($this->comment->isDownVoted()) {
|
||||
$this->comment->removeDownVote();
|
||||
return ;
|
||||
}
|
||||
|
||||
if ($this->comment->isUpVoted()) {
|
||||
$this->comment->removeUpVote();
|
||||
}
|
||||
|
||||
$this->comment->upvotes()->create([
|
||||
'user_id' => auth()->id(),
|
||||
'comment_id' => $this->comment->id,
|
||||
'type' => 'downvote'
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user