Files
eatvio-infra/app/Livewire/Diary/ConsultantCommentsEdit.php
2023-10-04 17:57:09 +03:00

62 lines
1.5 KiB
PHP

<?php
namespace App\Livewire\Diary;
use Livewire\Component;
use App\Models\ConsultantDiaryComment;
use Illuminate\Support\Facades\Auth;
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();
}
}
}