forked from eatvio/eatvio-infra
41 lines
854 B
PHP
Executable File
41 lines
854 B
PHP
Executable File
<?php
|
|
|
|
namespace App\Livewire\Plan\Like;
|
|
|
|
use App\Models\Plan;
|
|
use Livewire\Attributes\On;
|
|
use Livewire\Component;
|
|
use Illuminate\View\View;
|
|
|
|
class AnnouncementFooter extends Component
|
|
{
|
|
public Plan $plan;
|
|
|
|
public function mount(Plan $plan): void
|
|
{
|
|
$this->plan = $plan;
|
|
}
|
|
|
|
public function render(): View
|
|
{
|
|
return view('livewire.plan.like.announcement-footer');
|
|
}
|
|
|
|
#[On('liked-footer')]
|
|
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,
|
|
]);
|
|
} else {
|
|
return;
|
|
}
|
|
|
|
$this->dispatch('liked-footer')->to('plan.like-count');
|
|
}
|
|
}
|