F
Filamentβ€’5w ago
Nuxnux

a weird problem with action

i have a simple action which change the state of a column
EditAction::make()
->hidden(fn (): bool => $this->record->reservation->close || $this->record->is_chosen)
->record($this->record)
->label('Change availibility')
->form([
ToggleButtons::make('availability')
->inline()
->required()
->options([
BookingStatus::Pending->value => BookingStatus::Pending->prettify(),
BookingStatus::NotAvailable->value => BookingStatus::NotAvailable->prettify(),
BookingStatus::Available->value => BookingStatus::Available->prettify(),
]),
])
->action(function (Booking $record, array $data): void {
$record->update([
'availability' => $data['availability'],
]);
})
->after(function (): void {
$this->bookingInfolist();
}),
EditAction::make()
->hidden(fn (): bool => $this->record->reservation->close || $this->record->is_chosen)
->record($this->record)
->label('Change availibility')
->form([
ToggleButtons::make('availability')
->inline()
->required()
->options([
BookingStatus::Pending->value => BookingStatus::Pending->prettify(),
BookingStatus::NotAvailable->value => BookingStatus::NotAvailable->prettify(),
BookingStatus::Available->value => BookingStatus::Available->prettify(),
]),
])
->action(function (Booking $record, array $data): void {
$record->update([
'availability' => $data['availability'],
]);
})
->after(function (): void {
$this->bookingInfolist();
}),
bookingInfoList() is used to refresh the infoList on the top after the change but i got this error after using it the problem is there is no collection on this action btw i use this action on a view page array_merge(): Argument #1 must be of type array, Illuminate\Database\Eloquent\Collection given if you got any idea
3 Replies
arnaudsf
arnaudsfβ€’4w ago
a collection is not an array, but you can use (array) $mycollection to convert it to array
ModestasV
ModestasVβ€’4w ago
You can also do $collection->toArray() to convert it πŸ™‚
arnaudsf
arnaudsfβ€’4w ago
Becareful that $collection->toArray() convert only the first level to array, not nested objects :/
Want results from more Discord servers?
Add your server