FilamentF
Filament3y ago
1 reply
Trauma Zombie

Is it possible to set additional attribute when creating model from select field?

This is my code:
Select::make('client_id')
    ->label('Klient')
    ->relationship('client', 'full_name')
    ->options(
        fn () => Client::query()
            ->when(auth()->user()->isBroker(), fn (Builder $query) => $query->whereBelongsTo(auth()->user(), 'broker'))
            ->pluck('full_name', 'id')
    )
    ->preload()
    ->createOptionForm(ClientResource::getFormSchema())
    ->searchable(['company']),

I have to set broker_id of auth()->user()->id to my Client model when is created with this select field.
Was this page helpful?