I am making comments system. with two double livewire components.
outer component contains command-line component …
see following code…
in comments-section.blade.php
<div>
@foreach ($post->comments as $comment)
@livewire('comment-line', [
'post' => $post,
'comment' => $comment,
], key($comment->id))
@endforeach
</div>
in CommandLine.php
public $post;
public $comment;
protected $listeners = [
'setdelete'
];
public function render()
{
return view('livewire.comment-line');
}
function mount( $post, $comment ) {
$this->post = $post;
$this->comment = $comment;
}
function setdelete( $commentid ){
$comment = Comment::findOrFail( $commentid);
$comment->delete();
}
in command-line.blade.php
<div
x-data="{ comment_id:null }"
@setdelete="
comment_id = $event.detail.comment_id ;
if( comment_id == {{ $comment->id }} ) {
window.livewire.emit('setdelete', comment_id );
}
"
>
{{ $comment->content }}
<div
@click="$dispatch('setdelete', { comment_id : '{{ $comment->id }}' } ); "
> DELETE !</div>
</div>
Whenever I trigger ‘setdelete’ on document, it show 404 error after deleting model.
Can you help me out?