How can I set the default value of a Select, when its hidden?

Select::make('status')
->label('Status')
->options(Status::all()->pluck('name', 'id'))
->searchable()
->default(Status::where('name', 'Pending')->first()->id)
->hiddenOn(['create','edit']),
// ->hiddenOn('create',),
// ->disabled(!auth()->user()->can('status_expense')),
Select::make('status')
->label('Status')
->options(Status::all()->pluck('name', 'id'))
->searchable()
->default(Status::where('name', 'Pending')->first()->id)
->hiddenOn(['create','edit']),
// ->hiddenOn('create',),
// ->disabled(!auth()->user()->can('status_expense')),
It shows up as null on the table
4 Replies
Dennis Koch
Dennis Koch2y ago
Sure. It's not on the page. If you still need a value use one of the mutation methods.
Matthew
MatthewOP2y ago
How do you mean?
Matthew
MatthewOP2y ago
This worked! Thank you
protected function mutateFormDataBeforeCreate(array $data): array
{
$data['status'] = Status::where('name', 'Pending')->first()->id;

return $data;
}
protected function mutateFormDataBeforeCreate(array $data): array
{
$data['status'] = Status::where('name', 'Pending')->first()->id;

return $data;
}
Want results from more Discord servers?
Add your server