forked from eatvio/eatvio-infra
35 lines
785 B
PHP
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');
|
|
}
|
|
}
|