F
Filament11mo ago
Zetto

Array of ID to Other Values in a Table Column

I use multi select that returns an array of id in create/edit pages, how do i change it to other values when viewing it in the tables column ? Or better yet return the name instead of id in create/edit
10 Replies
Vp
Vp11mo ago
Can you post your code.. I think you didn't set up relationship properly 😆
Zetto
Zetto11mo ago
I dont use relationship, or should i use it in this case? Basically I multi-search the names then store it inside array
Vp
Vp11mo ago
Post your code, read #✅┊rules for format, I am not sure your use case but yes relationship should do what you're looking for
Zetto
Zetto11mo ago

->multiple()
->searchable()
->getSearchResultsUsing(fn (string $search): array => User::where('name', 'like', "%{$search}%")->limit(50)->pluck('name', 'id')->toArray())
->getOptionLabelsUsing(fn (array $values): array => User::whereIn('id', $values)->pluck('name', 'id')->toArray()),

->multiple()
->searchable()
->getSearchResultsUsing(fn (string $search): array => User::where('name', 'like', "%{$search}%")->limit(50)->pluck('name', 'id')->toArray())
->getOptionLabelsUsing(fn (array $values): array => User::whereIn('id', $values)->pluck('name', 'id')->toArray()),
those are the ones i use in the create/edit forms
Vp
Vp11mo ago
This is how I did using relationship, hope you can have idea
Forms\Components\Select::make('children')
->multiple()
->required()
->options(Customer::query()->pluck('name_preview', 'id'))
->getOptionLabelsUsing(fn ($values): array => Customer::find($values)?->pluck('name_preview', 'id')->toArray())
->searchable(),
Forms\Components\Select::make('children')
->multiple()
->required()
->options(Customer::query()->pluck('name_preview', 'id'))
->getOptionLabelsUsing(fn ($values): array => Customer::find($values)?->pluck('name_preview', 'id')->toArray())
->searchable(),
Zetto
Zetto11mo ago
Thanks I mean it is showing correctly in the table, but it only shows the id, did u also customize the table column?
Vp
Vp11mo ago
Oh, we're talking about table right.. though it's form..
Zetto
Zetto11mo ago
Yeah, I know how to access the array outside filament, i just dont know how to use it on filaments table columns
Vp
Vp11mo ago
This is how I display in table
Tables\Columns\TextColumn::make('children.name')
->badge()
->searchable()
Tables\Columns\TextColumn::make('children.name')
->badge()
->searchable()
So, in my use-case, the relationship handles everything..
Zetto
Zetto11mo ago
hmm i see thanks