F
Filamentβ€’3mo 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
ErlichOPβ€’3mo ago
Wider screenshot
No description
Solution
Bruno Pereira
Bruno Pereiraβ€’3mo 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
ErlichOPβ€’3mo ago
Let me try.
Erlich
ErlichOPβ€’3mo ago
This is current situation. I leave this screenshot to show what changed
No description
Bruno Pereira
Bruno Pereiraβ€’3mo 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
ErlichOPβ€’3mo ago
I want to keep everything in ->relationship() but your solution helped me. Thank you very much
No description
Erlich
ErlichOPβ€’3mo ago
Here is what I changed
No description
Bruno Pereira
Bruno Pereiraβ€’3mo ago
cool
Erlich
ErlichOPβ€’3mo ago
Thanks to you
Bruno Pereira
Bruno Pereiraβ€’3mo ago
if that's the solution don't forget to mark it as such
Erlich
ErlichOPβ€’3mo ago
I put πŸ‘ to you answer anything else should I do?
Bruno Pereira
Bruno Pereiraβ€’3mo ago
right click on the message hover apps -> mark as solution so that discord can clear the list for pending posts
Erlich
ErlichOPβ€’3mo ago
Okay. I did and I will keep this in my mind. Thank you
Want results from more Discord servers?
Add your server