forked from eatvio/eatvio-infra
36 lines
678 B
PHP
36 lines
678 B
PHP
<?php
|
|
|
|
namespace App\Livewire\Plan;
|
|
|
|
use App\Models\Plan;
|
|
use Livewire\Component;
|
|
|
|
class Like extends Component
|
|
{
|
|
public Plan $plan;
|
|
|
|
public function mount(Plan $plan)
|
|
{
|
|
$this->plan = $plan;
|
|
}
|
|
|
|
public function render()
|
|
{
|
|
return view('livewire.plan.like');
|
|
}
|
|
|
|
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');
|
|
}
|
|
}
|