What is the default method expecting when passing an array?

I'm trying to use the default method on a select to pass in the items that were previously selected and need to be populated in the select. However, I'm not sure what format the select is expecting. It's not working, and it's breaking the select entirely (nothing shows up in the dropdown).
public function form(Form $form): Form
{
return $form->schema([
Select::make('account')->options($this->getData())
->searchable()
->multiple()
->hintAction(
Action::make('refreshAccounts')
->label('Refresh from Quickbooks')
->icon('heroicon-o-arrow-path')
->action(function () {
$this->getData(forceRefresh: true);
})
)
->default(fn () => $this->getSelectedAccounts())
])->statePath('data');
}
public function form(Form $form): Form
{
return $form->schema([
Select::make('account')->options($this->getData())
->searchable()
->multiple()
->hintAction(
Action::make('refreshAccounts')
->label('Refresh from Quickbooks')
->icon('heroicon-o-arrow-path')
->action(function () {
$this->getData(forceRefresh: true);
})
)
->default(fn () => $this->getSelectedAccounts())
])->statePath('data');
}
This is what's in the returned array from $this->getSelectedAccounts():
array (
172 => 'Accounting',
113 => 'Accounts Payable',
84 => 'Accounts Receivable (A/R)',
127 => 'Accrued Taxes Payable',
217 => 'Amortization Expense',
)
array (
172 => 'Accounting',
113 => 'Accounts Payable',
84 => 'Accounts Receivable (A/R)',
127 => 'Accrued Taxes Payable',
217 => 'Amortization Expense',
)
which matches the format of the array that I'm using to populate the select. Not sure what I'm doing wrong.
Solution:
try ->default([172, 113...])
Jump to solution
1 Reply
Solution
LeandroFerreira
LeandroFerreira8mo ago
try ->default([172, 113...])