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(); } } }