is there a method to display the value of selectColumn read_only in table?
I have a select in the forms that works to get the user id of several related records . I would like to display in the table the user name not the user id
9 Replies
Filament
Column relationships - Columns - Table Builder - Filament
The elegant TALL stack table builder for Laravel artisans.
Trying a few things.
TextColumn::make('sectionLeader.last_name'),
gives me an empty column . my function for the relationship is public function sectionLeader(): BelongsTo
{
return $this->belongsTo(User::class, 'section_leader' );
}
Can you show the code of the select field please?
Sorry for the delay....
Select::make('sectionLeader')
->label('Section Leader')
->options(User::all()
->pluck('full_name', 'id'))
->searchable(),
Is sectionLeader a relationship, right? https://filamentphp.com/docs/2.x/forms/fields#populating-automatically-from-a-relationship
I'm not real clear on the how to of this one. I have this n the Set model
public function sectionLeader(): BelongsTo
{
return $this->belongsTo(User::class, 'section_leader' );
}
Trying a few things. TextColumn::make('sectionLeader.last_name'),
gives me an empty column .
I left out relationship! I'll try when I get home.
Nope the relationship()
is for the form, i need to look t that next but the table iview of the relationship is not workingyour database column name should be
section_leader_id
so that it does not clash with your relationship name
your relationship name should be sectionLeader
then use return $this->belongsTo(User::class, 'section_leader_id');
and Select::make('section_leader_id')
and TextColumn::make('sectionLeader.last_name')
I believe that the issue is the relationship as Dan said
https://laravel.com/docs/10.x/eloquent-relationships
Laravel - The PHP Framework For Web Artisans
Laravel is a PHP web application framework with expressive, elegant syntax. We’ve already laid the foundation — freeing you to create without sweating the small things.
@danharrin I changed the section_leader to section_leader_id and that resolved the name conflict. Thanks @Leandro Ferreira for the link!