F
Filament6mo ago
Lucky0

Toggle with eager loading in form

Why eager load works in table but not form? UserModel
public function notificationPreference(): HasOne
{
return $this->hasOne(UserNotificationPreference::class);
}
public function notificationPreference(): HasOne
{
return $this->hasOne(UserNotificationPreference::class);
}
UserResource
Forms\Components\Toggle::make('notificationPreference.is_enabled')
Forms\Components\Toggle::make('notificationPreference.is_enabled')
Is there any alternatives?
Solution:
Use ```php Group::make([ Toggle::make('is_enabled')...
Jump to solution
2 Replies
Solution
LeandroFerreira
LeandroFerreira6mo ago
Use
Group::make([
Toggle::make('is_enabled')
])->relationship('notificationPreference')
Group::make([
Toggle::make('is_enabled')
])->relationship('notificationPreference')
Lucky0
Lucky0OP6mo ago
Thank you, kind sire..
Forms\Components\Group::make([
Forms\Components\Toggle::make('is_enabled')
->label('Enable Notifications')
->formatStateUsing(fn ($record) => $record->is_enabled),
])
->relationship('notificationPreference'),
Forms\Components\Group::make([
Forms\Components\Toggle::make('is_enabled')
->label('Enable Notifications')
->formatStateUsing(fn ($record) => $record->is_enabled),
])
->relationship('notificationPreference'),
Want results from more Discord servers?
Add your server