Files
eatvio-infra/app/Livewire/Plan/Comment/Create.php
2023-12-14 14:00:50 +03:00

41 lines
891 B
PHP

<?php
namespace App\Livewire\Plan\Comment;
use Livewire\Component;
use App\Models\Plan;
use App\Models\PlanComment;
use App\Models\User;
use Livewire\Attributes\Validate;
class Create extends Component
{
public Plan $plan;
public User $user;
public $body = '';
public $grade = 0;
public function render()
{
return view('livewire.plan.comment.create');
}
public function save()
{
$this->validate([
'body' => 'required|min:10',
'grade' => 'required',
]);
$comment = new PlanComment();
$comment->grade = $this->grade;
$comment->body = $this->body;
$comment->plan_id = $this->plan->id;
$comment->user_id = $this->user->id;
$comment->save();
$this->reset(['body', 'grade']);
$this->dispatch('commentAdded')->to('plan.comment.show');
}
}