F
Filament15mo ago
zito

default value on form select not populating

I am attempting to have a value preselected when the Select item loads on a form. I only found two references to the default function in the docs, but no explanation on how to use it. I assume you pass an item that is in the options collection. Here is a snippet of what I tried: $roles = Role::all()->pluck('name', 'id'); $defaultRole = $roles->first(); Select::make('role') ->options($roles) ->default($defaultRole) Any reason why this isn't populating the default value?
5 Replies
zito
zitoOP15mo ago
my mistake, I was able to figure it out ->relationship('roles','name')
tuto1902
tuto190215mo ago
One small tip:
// You can call pluck directly on the query instead of the resulting collection
// This way you won't get any errors from phpstan
$roles = Role::pluck('name', 'id')
// You can call pluck directly on the query instead of the resulting collection
// This way you won't get any errors from phpstan
$roles = Role::pluck('name', 'id')
zito
zitoOP15mo ago
I didn't know that filament would automatically populate the value for me, that's convenient
tuto1902
tuto190215mo ago
just in case you need it somewhere else
zito
zitoOP15mo ago
nice I'll try that out. Thank you for the tip
Want results from more Discord servers?
Add your server