function in getOptionLabelFromRecordUsing() not working - Relationship of a Relationship

I need help, please. This is my Select:
Select::make('interviniente_id')
->relationship('interviniente', 'id')
->options(fn (Get $get): Collection => Interviniente::query()
->where('expediente_id', $get('expediente_id'))
->pluck('interviniente_id', 'id'))
->getOptionLabelFromRecordUsing(function ($value): ?string {
$persona = Persona::find($value);
return $persona->nombreCompleto;
})
->label(__('Interviniente'))
->preload()
->searchable(),
Select::make('interviniente_id')
->relationship('interviniente', 'id')
->options(fn (Get $get): Collection => Interviniente::query()
->where('expediente_id', $get('expediente_id'))
->pluck('interviniente_id', 'id'))
->getOptionLabelFromRecordUsing(function ($value): ?string {
$persona = Persona::find($value);
return $persona->nombreCompleto;
})
->label(__('Interviniente'))
->preload()
->searchable(),
It is showing the values for the field in the pluck('interviniente_id') but it is not showing the $persona->nombreCompleto. In the dropdown I see ids corresponding with "Persona" model ids (which is OK), so I only need to get those ids it is showing and replace them by the names or names and surnames of the persona model. No matter what I put in the getOptionLabelFromRecordUsing function, it always shows the same. I have also tried with getOptionLabelsUsing and nothing works. My relationships are MODEL_01 belongsTo MODEL_02 which also belongsTo MODEL_03, so how can I put the name of the field I need to retrieve? MODEL_01->MODEL_02->MODEL_03->fieldName or MODEL_01.MODEL_02.MODEL_03.fieldName ??? Nothing is working for me in that Select. Any help will be highly appreciated. Many thanks.
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server