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