Files
eatvio-infra/app/Livewire/Plan/Comment/Create.php
Anatoliy Poloz ec216293ef plan styling fix
2023-12-20 11:23:12 +03:00

54 lines
1004 B
PHP

<?php
namespace App\Livewire\Plan\Comment;
use App\Models\Plan;
use App\Models\PlanComment;
use App\Models\User;
use Livewire\Component;
class Create extends Component
{
public Plan $plan;
public User $user;
public $body = '';
public $grade;
public $isChecked = false;
public function render()
{
return view('livewire.plan.comment.create');
}
public function toggle()
{
$this->isChecked = ! $this->isChecked;
}
public function save()
{
$this->validate([
'body' => 'required|min:3',
'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(['grade', 'body']);
$this->toggle();
$this->dispatch('commentAdded')->to('plan.comment.show');
}
}