'' ]; public $isEditing = false; public $editState = [ 'body' => '' ]; protected $listeners = [ 'refresh' => '$refresh' ]; protected $validationAttributes = [ 'replyState.body' => 'reply' ]; public function updatedIsEditing($isEditing) { if (! $isEditing) { return; } $this->editState = [ 'body' => $this->comment->body ]; } public function editComment() { $this->authorize('update', $this->comment); $this->comment->update($this->editState); $this->isEditing = false; } public function deleteComment() { $this->authorize('destroy', $this->comment); $this->comment->delete(); $this->dispatch('refresh'); } public function postReply() { if (! $this->comment->depth() < 2) { return; } $this->validate([ 'replyState.body' => 'required' ]); $reply = $this->comment->children()->make($this->replyState); $reply->user()->associate(auth()->user()); $reply->commentable()->associate($this->comment->commentable); $reply->save(); $this->replyState = [ 'body' => '' ]; $this->isReplying = false; $this->dispatch('refresh')->self(); } public function render() { return view('livewire.comment'); } }