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
ddoddsr
ddoddsrOP2y ago
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' ); }
LeandroFerreira
Can you show the code of the select field please?
ddoddsr
ddoddsrOP2y ago
Sorry for the delay....Select::make('sectionLeader') ->label('Section Leader') ->options(User::all() ->pluck('full_name', 'id')) ->searchable(),
LeandroFerreira
Filament
Fields - Form Builder - Filament
The elegant TALL stack form builder for Laravel artisans.
ddoddsr
ddoddsrOP2y ago
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 working
Dan Harrin
Dan Harrin2y ago
your 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')
LeandroFerreira
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.
ddoddsr
ddoddsrOP2y ago
@danharrin I changed the section_leader to section_leader_id and that resolved the name conflict. Thanks @Leandro Ferreira for the link!
Want results from more Discord servers?
Add your server