Files
eatvio-infra/app/Livewire/Diet/Comment/Create.php

47 lines
951 B
PHP

<?php
namespace App\Livewire\Diet\Comment;
use App\Models\Diet;
use App\Models\DietComment;
use App\Models\User;
use Illuminate\View\View;
use Livewire\Component;
class Create extends Component
{
public Diet $diet;
public User $user;
public string $body = '';
public string|int $grade = 0;
public bool $isChecked = true;
public function render(): View
{
return view('livewire.diet.comment.create');
}
public function toggle(): void
{
$this->isChecked ? false : true;
}
public function save(): void
{
$this->toggle();
$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');
}
}