forked from eatvio/eatvio-infra
37 lines
742 B
PHP
37 lines
742 B
PHP
<?php
|
|
|
|
namespace App\Http\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->emitTo('recipe.like-count', 'liked');
|
|
}
|
|
}
|