forked from eatvio/eatvio-infra
37 lines
743 B
PHP
37 lines
743 B
PHP
<?php
|
|
|
|
namespace App\Livewire\Recipe;
|
|
|
|
use Livewire\Component;
|
|
use App\Models\Recipe;
|
|
|
|
class Like extends Component
|
|
{
|
|
public Recipe $recipe;
|
|
public $isIconOnly = false;
|
|
|
|
public function mount(Recipe $recipe)
|
|
{
|
|
$this->recipe = $recipe;
|
|
}
|
|
|
|
public function render()
|
|
{
|
|
return view('livewire.recipe.like');
|
|
}
|
|
|
|
public function like(): void
|
|
{
|
|
if ($this->recipe->isLiked()) {
|
|
$this->recipe->removeLike();
|
|
} elseif (auth()->user()) {
|
|
$this->recipe->likes()->create([
|
|
'user_id' => auth()->id(),
|
|
'blog_post_id' => $this->recipe->id
|
|
]);
|
|
}
|
|
|
|
$this->dispatch('liked')->to('recipe.like-count');
|
|
}
|
|
}
|