Files
eatvio-infra/app/Livewire/Diet/Comment/Create.php
2023-10-04 17:57:09 +03:00

35 lines
742 B
PHP

<?php
namespace App\Livewire\Diet\Comment;
use Livewire\Component;
use App\Models\Diet;
use App\Models\DietComment;
use App\Models\User;
class Create extends Component
{
public Diet $diet;
public User $user;
public $body = '';
public $grade = 0;
public function render()
{
return view('livewire.diet.comment.create');
}
public function save()
{
$comment = new DietComment();
$comment->grade = $this->grade;
$comment->body = $this->body;
$comment->diet_id = $this->diet->id;
$comment->user_id = $this->user->id;
$comment->save();
$this->reset(['body', 'grade']);
$this->dispatch('commentAdded')->to('diet.comment.show');
}
}