F
Filamentβ€’2mo 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
Groliβ€’2mo ago
Does anyone know?
Solution
Dennis Koch
Dennis Kochβ€’2mo ago
I think it should be public function handleChoosePerson($similarPerson, $newPerson).
Groli
Groliβ€’2mo ago
oh okay, thank you, I didn't know it could be done like that...
Dennis Koch
Dennis Kochβ€’2mo ago
So it did work? πŸ˜…
Groli
Groliβ€’2mo ago
Yeah, at first I didn't understand correctly
Dennis Koch
Dennis Kochβ€’2mo ago
Livewire uses each item as an argument
Groli
Groliβ€’2mo ago
what you've ment sorry I though you were talking about something else my bad Thank you!
Dennis Koch
Dennis Kochβ€’2mo ago
No worries. Good you noticed
Want results from more Discord servers?
Add your server