Files
eatvio-infra/app/Livewire/Diary/ConsultantCommentsEdit.php
Anatoliy Poloz 92a54106ef analysators added
2023-12-18 14:36:32 +03:00

73 lines
1.5 KiB
PHP

<?php
namespace App\Livewire\Diary;
use App\Models\ConsultantDiaryComment;
use Illuminate\Support\Facades\Auth;
use Livewire\Component;
class ConsultantCommentsEdit extends Component
{
public $daysCount;
public $diary;
public $curMeals;
public $typeNames;
public $comments = [];
public $retireComment = '';
public $breakfastComment = '';
public $dinnerComment = '';
public $supperComment = '';
public $lunchComment = '';
public $snacksComment = '';
public $totalComment = '';
public function mount()
{
$this->comments = (new ConsultantDiaryComment())->where(
'user_id',
Auth::id()
)->where(
'diary_id',
$this->diary->id
)->pluck('comment', 'comment_type')->toArray();
}
public function render()
{
$commentTypes = ['breakfast', 'dinner', 'supper', 'lunch', 'snacks', 'wakeup_time', 'total'];
return view(
'livewire.diary.consultant-comments-edit',
[
'commentTypes' => $commentTypes,
]
);
}
public function save()
{
foreach ($this->comments as $key => $comment) {
$updateComment = ConsultantDiaryComment::updateOrCreate(
[
'user_id' => Auth::id(),
'diary_id' => $this->diary->id,
'comment_type' => $key,
],
['comment' => $comment]
);
$updateComment->save();
}
}
}