Select automatically select the first one

Hello, Given this example:
Select::make('author_id')
->label('Author')
->options(User::all()->pluck('name', 'id'))
->searchable()
Select::make('author_id')
->label('Author')
->options(User::all()->pluck('name', 'id'))
->searchable()
In case there is only one user. Is it possible to automatically set the value of the select to that user? Thanks .
2 Replies
awcodes
awcodes9mo ago
You could use ->default() to test and set it. Honestly though, if there’s only one user I would just hide it and set the value during the record creation to the authenticated user.
JJSanders
JJSandersOP9mo ago
True. I will try default. I have more use cases for this then just the authenticated user. But if default accepts a closure then I will be able to solve it.
Want results from more Discord servers?
Add your server