forked from eatvio/eatvio-infra
35 lines
762 B
PHP
35 lines
762 B
PHP
<?php
|
|
|
|
namespace App\Livewire\Recipe\Comment;
|
|
|
|
use Livewire\Component;
|
|
use App\Models\Recipe;
|
|
use App\Models\RecipeComment;
|
|
use App\Models\User;
|
|
|
|
class Create extends Component
|
|
{
|
|
public Recipe $recipe;
|
|
public User $user;
|
|
public $body = '';
|
|
public $grade = 0;
|
|
|
|
public function render()
|
|
{
|
|
return view('livewire.recipe.comment.create');
|
|
}
|
|
|
|
public function save()
|
|
{
|
|
$comment = new RecipeComment();
|
|
$comment->grade = $this->grade;
|
|
$comment->body = $this->body;
|
|
$comment->recipe_id = $this->recipe->id;
|
|
$comment->user_id = $this->user->id;
|
|
$comment->save();
|
|
|
|
$this->reset(['body', 'grade']);
|
|
$this->dispatch('commentAdded')->to('recipe.comment.show');
|
|
}
|
|
}
|