I am trying to emit an event that gets 2 parameters.
I get the error:
Unable to resolve dependency [Parameter #1 [ $id ]] in class App\Http\Livewire\MyClass
My component event code:
protected $listeners = ['deleteSupplier'];
...
public function deleteSupplier($key, $id)
{
dd($key); //trying to debug what is going on
}
For testing I defaulted the $id parameter and then the dd($key) gave me an array:
//this gives:
array:2 [▼
0 => 0
1 => 9
My blade:
@foreach($beanSuppliers as $key => $sup)
<p><a href="#" wire:click="$emit('deleteSupplierTriggered', {{ $key }}, {{ $sup['id'] }}, '{{ $sup['name'] }}')">
<i class="fas fa-trash-alt" aria-hidden="true"></i>
</a></p>
@endforeach
Inspecting a line in firebug shows:
wire:click="$emit('deleteSupplierTriggered', 0, 9, 'Seven Oaks')"
which is correct.
<script>
Livewire.on("deleteSupplierTriggered", (key, id, removeName) => {
// for testing I tried: alert(id) it gives the right value
Swal.fire({
title: 'Confirm Remove',
text: `Are you sure you want to remove: ${removeName}`,
icon: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Yes, remove it!'
}).then(result => {
if (result.value) {
Livewire.emit("deleteSupplier", [key, id]);
}
});
});
</script>
What am I doing wrong?