© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•2y ago•
1 reply
nowak

Using nested relationship as option labels / titleAttribute for Select field

I have a relationship Select field in my form that stores product_sku_id which is the id for my ProductSku model. My ProductSku model does not store attribute values, like
Small
Small
or
Large
Large
, because those are stored in the AttributeValue model, which ProductSku has a ManyToMany relationship with.

So I can easily use the
sku
sku
attribute as the titleAttribute for the option labels, as it is an attribute on the ProductSku model. But I want to use
ProductSku::attributeValues->value
ProductSku::attributeValues->value
as the titleAttribute instead. Is there a way to achieve this by using eloquent relationships? Or am I forced to store the attribute values on the product_skus table directly to make this work?

Here is my current product_sku_id Select field with a hopeful attempt to get this to work, but unsuccessfully:
Select::make('product_sku_id')
  ->label('SKU')
  ->relationship('productSku', 'attributeValues.value')
  ->live()
  ->afterStateUpdated(function ($state, Set $set, Get $get) {
      \Log::info('sku state', ['state' => $state]);
      $set ('price', ProductSku::find($state)?->price ?? 0);
  })
  ->required(),
Select::make('product_sku_id')
  ->label('SKU')
  ->relationship('productSku', 'attributeValues.value')
  ->live()
  ->afterStateUpdated(function ($state, Set $set, Get $get) {
      \Log::info('sku state', ['state' => $state]);
      $set ('price', ProductSku::find($state)?->price ?? 0);
  })
  ->required(),


I have seen people using something like this to save data to relationships:
Group::make()
  ->relationship('metadata')
  ->schema([
      Select::make()
Group::make()
  ->relationship('metadata')
  ->schema([
      Select::make()

But I am not sure if and how this could be used for my use case, as I still need my select field to store the


product_sku_id`.

Any help is highly appreciated!
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Displaying nested attributes on Select relationship field
FilamentFFilament / ❓┊help
2y ago
AttachAction custom select option labels
FilamentFFilament / ❓┊help
3y ago
Filament Select with Relationship: Custom Label for titleAttribute Options
FilamentFFilament / ❓┊help
14mo ago
Null option for Select Field
FilamentFFilament / ❓┊help
3y ago