It seems like you're encountering an issue with Livewire's entanglement with Alpine.js, which is causing the error messages you're seeing. The mountedActionsData property is likely not being properly updated or recognized by Livewire, which is why you're getting the "cannot be found on component" error.
Here's a potential solution to address the issues you're facing:
-
Ensure that the
childAttendeesproperty is properly initialized as a collection. Since you're using it as an array or collection, it's best to initialize it as a collection in the constructor of your Livewire component. -
Use Livewire's
wire:modelorwire:clickdirectives to handle the toggles instead of using$entangle. This will simplify the state management and avoid the entanglement issues. -
To show a message when the attendee is not found, you can use a Livewire property to track whether the attendee has been found and display a message conditionally in your Blade template.
Here's how you might adjust your code:
class Home extends Component implements HasForms, HasActions
{
use InteractsWithActions;
use InteractsWithForms;
public ?Attendee $attendee = null;
public Collection $childAttendees;
public bool $attendeeNotFound = false;
public function mount()
{
$this->childAttendees = collect();
}
public function rsvpAction(): Action
{
// ... other code ...
Step::make('Name')
// ... other code ...
->afterStateUpdated(function (Set $set, $state) {
$this->attendee = Attendee::where('name', $state)->first();
if ($this->attendee) {
$this->attendeeNotFound = false;
$this->childAttendees = $this->attendee->isMain()
? $this->attendee->childAttendees
: $this->attendee->mainAttendee->childAttendees;
} else {
$this->attendeeNotFound = true;
$this->childAttendees = collect();
}
})
// ... other code ...
Step::make('Attendance')
// ... other code ...
->schema(function (Get $get) {
$schema = [];
$attendee = $get('attendee');
$childAttendees = $get('childAttendees');
if (!$attendee || $childAttendees->isEmpty()) {
return [];
}
$schema[] = Toggle::make('willAttend')
->label('Will you attend?')
->reactive();
foreach ($childAttendees as $childAttendee) {
$schema[] = Toggle::make("childAttendees.{$childAttendee->id}.rsvp")
->label("Will {$childAttendee->name} also attend?")
->reactive();
}
return $schema;
})
// ... other code ...
}
// ... other code ...
}
In your Blade template, you can conditionally show a message if the attendee is not found:
@if($this->attendeeNotFound)
<div class="alert alert-warning">
Attendee not found. Please check the name and try again.
</div>
@endif
Remember to replace the ->reactive() method with the appropriate Livewire directives if needed, such as wire:model or wire:click, depending on how you want to handle the state of your toggles.
This solution should help you manage the state of your component more effectively and display messages to the user when necessary.