Preload BelongsToMany relationship on Edit Page

Sorry if this has already been answered but couldn't find when searching. I have a edit page that I am showing a comma-separated list of a belongs to many relationship and want to add/edit the relationship from an Action modal. I'm using a callback in the placeholder to render the comma-separated list but the relationship IDs aren't loaded but when I add a CheckboxList component next to it, the placeholder will then render the text. I assume Filament is only loading relationships when needed, which makes sense, but in this case I'd like to preload the relationship so values are available on the edit page as well as the action modal to actually set these. Is there a way to preload the relationship or is there a better alternative to satisfy this requirement? Resource form schema
Forms\Components\Placeholder::make('Staff')
->content(function (Forms\Get $get): ?string {
if ($userIds = $get('users')) {
return User::whereIn('id', $userIds)->pluck('name')->join(', ');
}
return '';
}),
Forms\Components\Placeholder::make('Staff')
->content(function (Forms\Get $get): ?string {
if ($userIds = $get('users')) {
return User::whereIn('id', $userIds)->pluck('name')->join(', ');
}
return '';
}),
Form actions
Actions::make([
Action::make('Add Resources')
->button()
->outlined()
->form(function(Assignment $record){
// more work to be done here
return [
Forms\Components\CheckboxList::make('users')->relationship('users', 'name')
];
})
])
Actions::make([
Action::make('Add Resources')
->button()
->outlined()
->form(function(Assignment $record){
// more work to be done here
return [
Forms\Components\CheckboxList::make('users')->relationship('users', 'name')
];
})
])
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server