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

35 lines
785 B
PHP

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