© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•3y ago•
1 reply
Brian Kidd

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')
      ];
   })
])
Screenshot_2023-08-26_at_10.26.48_AM.png
Screenshot_2023-08-26_at_10.27.57_AM.png
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

BelongsToMany Relationship Cast Problem on Edit Record
FilamentFFilament / ❓┊help
3y ago
Relationship belongstoMany
FilamentFFilament / ❓┊help
3y ago
Select Field relationship on edit page
FilamentFFilament / ❓┊help
2y ago
unknown field on BelongsToMany relationship
FilamentFFilament / ❓┊help
3y ago