forked from eatvio/eatvio-infra
38 lines
765 B
PHP
Executable File
38 lines
765 B
PHP
Executable File
<?php
|
|
|
|
namespace App\Livewire\Plan\Like;
|
|
|
|
use App\Models\Plan;
|
|
use Livewire\Attributes\On;
|
|
use Livewire\Component;
|
|
|
|
class AnnouncementFooter extends Component
|
|
{
|
|
public Plan $plan;
|
|
|
|
public function mount(Plan $plan)
|
|
{
|
|
$this->plan = $plan;
|
|
}
|
|
|
|
public function render()
|
|
{
|
|
return view('livewire.plan.like.announcement-footer');
|
|
}
|
|
|
|
#[On('liked')]
|
|
public function like(): void
|
|
{
|
|
if ($this->plan->isLiked()) {
|
|
$this->plan->removeLike();
|
|
} elseif (auth()->user()) {
|
|
$this->plan->likes()->create([
|
|
'user_id' => auth()->id(),
|
|
'plan_id' => $this->plan->id,
|
|
]);
|
|
}
|
|
|
|
$this->dispatch('liked')->to('plan.like-count');
|
|
}
|
|
}
|