| Current Path : /home/forge/stage.sksb.smartcon-survey.com/app/Livewire/ |
| Current File : /home/forge/stage.sksb.smartcon-survey.com/app/Livewire/OpenAnswers.php |
<?php
namespace App\Livewire;
use App\Models\Comment;
use Livewire\Component;
class OpenAnswers extends Component
{
public $selected = [];
public $disableShow = true;
public function render()
{
$this->disableShow = count($this->selected) === 0;
$comments = Comment::where('show', 0)
->where('text', '!=', null)
->with('topic')
->orderByDesc('id')
->get();
return view('livewire.open-answers', ['comments' => $comments]);
}
public function saveData()
{
if (count($this->selected) > 0) {
foreach ($this->selected as $commentId) {
Comment::showComment($commentId);
}
session()->flash('comment_success', 'Die Daten wurden erfolgreich gespeichert.');
}
}
public function updateComment(int $id, string $newComment): void
{
Comment::updateComment($id, $newComment);
session()->flash('comment_success', 'Das Antwort wurde erfolgreich aktualisiert.');
}
public function deleteInterview(int $commentId)
{
Comment::hideComment($commentId);
session()->flash('comment_success', 'Die Antwort wurden erfolgreich gelöscht.');
return redirect(route('openanswers.index'));
}
public function toggleAllCheckboxes(bool $checkboxStatus): void
{
if ($checkboxStatus === false || count($this->selected) > 0) {
$this->selected = [];
} else {
$comments = Comment::where('show', 0)->with('topic')->get();
foreach ($comments as $comment) {
$this->selected[] = $comment->id;
}
}
}
}