F
Filament6mo ago
Erlich

How to use another relation's column as titleAttribute in Select

Hello everyone. Please check my first screenshot. As you see, I list unused permissions in Forms\Components\Select But my permission also have this relation: permission->permissionLanguages->where('language_id', Auth::user()->language->id)->first()->name How can I use name column of permissionLanguages as titleAttribute?
No description
Solution:
try using this
->getOptionLabelFromRecordUsing(fn (Model $record) => "{$record->permissionLanguages->where('language_id', Auth::user()->language->id)->first()->name}")
->getOptionLabelFromRecordUsing(fn (Model $record) => "{$record->permissionLanguages->where('language_id', Auth::user()->language->id)->first()->name}")
...
Jump to solution
14 Replies
Erlich
ErlichOP6mo ago
Wider screenshot
No description
Solution
Bruno Pereira
Bruno Pereira6mo ago
try using this
->getOptionLabelFromRecordUsing(fn (Model $record) => "{$record->permissionLanguages->where('language_id', Auth::user()->language->id)->first()->name}")
->getOptionLabelFromRecordUsing(fn (Model $record) => "{$record->permissionLanguages->where('language_id', Auth::user()->language->id)->first()->name}")
something like that
Erlich
ErlichOP6mo ago
Let me try.
Erlich
ErlichOP6mo ago
This is current situation. I leave this screenshot to show what changed
No description
Bruno Pereira
Bruno Pereira6mo ago
wait that's not the thing you asked, I tought you wanted the select label to be the name, you want the titleAttribute: 'code' to be titleAttribute: something else Don't know if it's possible if the field only accepts a string
Erlich
ErlichOP6mo ago
I want to keep everything in ->relationship() but your solution helped me. Thank you very much
No description
Erlich
ErlichOP6mo ago
Here is what I changed
No description
Bruno Pereira
Bruno Pereira6mo ago
cool
Erlich
ErlichOP6mo ago
Thanks to you
Bruno Pereira
Bruno Pereira6mo ago
if that's the solution don't forget to mark it as such
Erlich
ErlichOP6mo ago
I put 👍 to you answer anything else should I do?
Bruno Pereira
Bruno Pereira6mo ago
right click on the message hover apps -> mark as solution so that discord can clear the list for pending posts
Erlich
ErlichOP6mo ago
Okay. I did and I will keep this in my mind. Thank you

Did you find this page helpful?