set default value for select
I cannot figure out how to set the default value for a select. I've tried both:
and
Neither seems to actually set the default value.
6 Replies
First of all, you should use the value you gave to your options for the default selection.
What does StatusEnum::DRAFT->value return?
and StatusEnum::class
It's an enum.
We can try this to determine where the error is.;
Select::make('status')
->options([
'draft' => 'Draft',
'scheduled' => 'Scheduled',
'published' => 'Published',
])
->default('draft')
Try this first and look for is it fixed.
Apparently there is no error in the enum. You can try to dd(enum) for is it right return
No that does not work either
Actually, I have never tried to give a default value to select before. I did not need this as I filled out my form during the mount() phase of my Livewire component. If it's something you can do, move your form to a livewire component and assign a value to your select in mount().
I have no other advice to give in this situation.
are you using on the create page or is it a custom page?