© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•2y ago•
14 replies
Daniel Veselinov

Adding a Filament form (select component) to a Livewire(v3.x) component

Hi everyone,

I'm trying to implement Filament forms in my livewire component.
What I'm trying to do?
I'm using a filament select component with multiple choices linked to a relation. After saving, the 'interests' aren't displayed upon page refresh, despite being correctly synced in the database. However, when viewed through the filament admin panel, the selected interests are displayed correctly.

class UpdateInterestForm extends Component implements HasForms 
{ 
  use InteractsWithForms;

  public User $user;
  public $interests;
  
  public function mount(): void
  {
      $this->user = Auth::user();
  }
  
  public function updateInterestUser(): void
  {
      $this->user->interests()->sync($this->interests);
  
      $this->dispatch('saved');
  }
  
  public function form(Form $form): Form
  {
      return $form
            ->schema([
                Select::make('interests')
                    ->multiple()
                    ->preload()
                    ->relationship('interests', 'name')
                    ->minItems(1)
                    ->maxItems(15)
            ])
            ->model(User::class);
  }
  
  public function render(): View
  {
      return view('livewire.profile.update-interest-form');
  }
}
class UpdateInterestForm extends Component implements HasForms 
{ 
  use InteractsWithForms;

  public User $user;
  public $interests;
  
  public function mount(): void
  {
      $this->user = Auth::user();
  }
  
  public function updateInterestUser(): void
  {
      $this->user->interests()->sync($this->interests);
  
      $this->dispatch('saved');
  }
  
  public function form(Form $form): Form
  {
      return $form
            ->schema([
                Select::make('interests')
                    ->multiple()
                    ->preload()
                    ->relationship('interests', 'name')
                    ->minItems(1)
                    ->maxItems(15)
            ])
            ->model(User::class);
  }
  
  public function render(): View
  {
      return view('livewire.profile.update-interest-form');
  }
}


Relation in the User model:

php 
public function interests(): BelongsToMany { return $this->belongsToMany(Interest::class); }
php 
public function interests(): BelongsToMany { return $this->belongsToMany(Interest::class); }


Relation in the Interest model:

php 
public function users(): BelongsToMany { return $this->belongsToMany(User::class); }
php 
public function users(): BelongsToMany { return $this->belongsToMany(User::class); }


Note: this very code, Select::make('interests').. in my UserResource filament works just fine, the problem is in the Livewire component.

Filament - UserResource
!image

Livewire -
!image
Preview image
Preview image
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

Adding form to livewire component
FilamentFFilament / ❓┊help
3y ago
Adding a form to a Livewire component
FilamentFFilament / ❓┊help
12mo ago
Adding a form to a Livewire component
FilamentFFilament / ❓┊help
2y ago
Adding a form to a Livewire component
FilamentFFilament / ❓┊help
2y ago