F
Filament8mo ago
Groli

Possible bug in communication with livewire while passing data through dispatch?

I'm trying to dispatch event and provide an array with keys and values as data in notification action. This is where I'm setting up the action:
...
foreach ($similarPeople as $similarPerson) {
$chooseActions[] = Action::make($similarPerson->id)
->button()
->label($similarPerson->id)
->dispatch('choosePerson', ['similarPerson'=>$similarPerson->toArray(), 'newPerson'=>$newPerson]);
}
...
...
foreach ($similarPeople as $similarPerson) {
$chooseActions[] = Action::make($similarPerson->id)
->button()
->label($similarPerson->id)
->dispatch('choosePerson', ['similarPerson'=>$similarPerson->toArray(), 'newPerson'=>$newPerson]);
}
...
If I do it like this, I get this error: Unable to resolve dependency [Parameter #0 [ <required> $data ]] in class ... But if I put the data array into another array like this:
->dispatch('choosePerson', [['similarPerson'=>$similarPerson->toArray(), 'newPerson'=>$newPerson]])
->dispatch('choosePerson', [['similarPerson'=>$similarPerson->toArray(), 'newPerson'=>$newPerson]])
Then I get it correctly, verified with debug (see the image).
public function handleChoosePerson($data)
{
dd($data);
}
public function handleChoosePerson($data)
{
dd($data);
}
I think this might be some kind of mistake, but correct me if I'm wrong, or doing something wrong please.
No description
Solution:
I think it should be public function handleChoosePerson($similarPerson, $newPerson).
Jump to solution
8 Replies
Groli
GroliOP8mo ago
Does anyone know?
Solution
Dennis Koch
Dennis Koch8mo ago
I think it should be public function handleChoosePerson($similarPerson, $newPerson).
Groli
GroliOP8mo ago
oh okay, thank you, I didn't know it could be done like that...
Dennis Koch
Dennis Koch8mo ago
So it did work? 😅
Groli
GroliOP8mo ago
Yeah, at first I didn't understand correctly
Dennis Koch
Dennis Koch8mo ago
Livewire uses each item as an argument
Groli
GroliOP8mo ago
what you've ment sorry I though you were talking about something else my bad Thank you!
Dennis Koch
Dennis Koch8mo ago
No worries. Good you noticed

Did you find this page helpful?