Ano po kaya problema sa code ko may error po "custom_livewire.js:61 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'emit')", hindi po na de delete ang data, im using laravel livewire po
Javascript
window.addEventListener('Swal
eletedRecord', event => {
Swal.fire({
title: 'Are you sure you want to delete this section: ' + event.detail[0].section_name + '?',
text: event.detail.title,
icon: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Yes, delete it!'
}).then((result) => {
if (result.isConfirmed) {
window.livewire.emit('RecordDeleted', event.detail[0].id)
Swal.fire(
'Deleted!:',
'Your file has been deleted.',
'success'
)
}
})
});
Back End
public function ConfirmDelete($section_id, $section_name) {
$this->dispatch('Swal
eletedRecord', [
'section_name' => $section_name,
'title' => 'Are You Sure You Want to Delete? <span class="text-danger">' . $section_name . '</span>',
'id' => $section_id,
]);
}
protected $listeners = ['RecordDeleted' => 'DeletedSection'];
public function RecordDeleted($section_id) {
$sectiondelete = SectionModel::find($section_id);
$sectiondelete->delete();
}
Front End
<table class="table" width="100%">
<thead>
<tr>
<th>Section Name</th>
<th>Action</th>
</tr>
</thead>
<tbody>
@forelse($sectionsdata as $section)
<tr>
<td>{{ $section->section_name }}</td>
<td>{{ $section->section_status === 1 ? 'Enabled' : 'Disabled' }}</td>
<td>
<div class="btn-group">
<a href="#editSection" data-toggle="modal" wire:click.prevent="editSection({{ $section->id }})" class="btn btn-info"><i class="fa fa-edit"></i></a>
<a href="#" wire:click.prevent="ConfirmDelete({{$section->id}}, '{{$section->section_name}}')" class="btn btn-danger"><i class="fa fa-trash"></i></a>
</div>
</td>
</tr>
@include('sections.edit')
empty
@endforelse
</tbody>
</table>
Javascript
window.addEventListener('Swal

Swal.fire({
title: 'Are you sure you want to delete this section: ' + event.detail[0].section_name + '?',
text: event.detail.title,
icon: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Yes, delete it!'
}).then((result) => {
if (result.isConfirmed) {
window.livewire.emit('RecordDeleted', event.detail[0].id)
Swal.fire(
'Deleted!:',
'Your file has been deleted.',
'success'
)
}
})
});
Back End
public function ConfirmDelete($section_id, $section_name) {
$this->dispatch('Swal

'section_name' => $section_name,
'title' => 'Are You Sure You Want to Delete? <span class="text-danger">' . $section_name . '</span>',
'id' => $section_id,
]);
}
protected $listeners = ['RecordDeleted' => 'DeletedSection'];
public function RecordDeleted($section_id) {
$sectiondelete = SectionModel::find($section_id);
$sectiondelete->delete();
}
Front End
<table class="table" width="100%">
<thead>
<tr>
<th>Section Name</th>
<th>Action</th>
</tr>
</thead>
<tbody>
@forelse($sectionsdata as $section)
<tr>
<td>{{ $section->section_name }}</td>
<td>{{ $section->section_status === 1 ? 'Enabled' : 'Disabled' }}</td>
<td>
<div class="btn-group">
<a href="#editSection" data-toggle="modal" wire:click.prevent="editSection({{ $section->id }})" class="btn btn-info"><i class="fa fa-edit"></i></a>
<a href="#" wire:click.prevent="ConfirmDelete({{$section->id}}, '{{$section->section_name}}')" class="btn btn-danger"><i class="fa fa-trash"></i></a>
</div>
</td>
</tr>
@include('sections.edit')
empty
@endforelse
</tbody>
</table>