F
Filamentβ€’8mo ago
Sidem

relation : How can i show the name and not the ID

Hi, My code is :
Select::make('suivi_user_maintenance')
->relationship('suivipar', 'name',
function ($query) {
$query->where('statut', 1)
->with('role')
->whereHas('role', function ($q) {
$q->whereIn('name', ['S', 'RS', 'AF', 'AT']);
})
->orderBy('name');
}
)
Select::make('suivi_user_maintenance')
->relationship('suivipar', 'name',
function ($query) {
$query->where('statut', 1)
->with('role')
->whereHas('role', function ($q) {
$q->whereIn('name', ['S', 'RS', 'AF', 'AT']);
})
->orderBy('name');
}
)
and i don"t know how show the name and not the id on the front : If you have any idees for helping me it will be nice πŸ™‚ thanks you
No description
4 Replies
bwurtz999
bwurtz999β€’8mo ago
Looks like you can use ->getOptionLabelFromRecordUsing
bwurtz999
bwurtz999β€’8mo ago
->getOptionLabelFromRecordUsing(function ($record) {
// return whatever label you want
})
->getOptionLabelFromRecordUsing(function ($record) {
// return whatever label you want
})
Iliyas M
Iliyas Mβ€’8mo ago
Try this
Select::make('suivi_user_maintenance')
->relationship('suivipar', 'name',
function ($query, $state) {
$query
->where(fn ($q) => $q->where('statut', 1)
->with('role')
->whereHas('role', function ($q) {
$q->whereIn('name', ['S', 'RS', 'AF', 'AT']))
->when($state, fn ($q, $value) => $q->orWhere('id', $value));
})
->orderBy('name');
}
)
Select::make('suivi_user_maintenance')
->relationship('suivipar', 'name',
function ($query, $state) {
$query
->where(fn ($q) => $q->where('statut', 1)
->with('role')
->whereHas('role', function ($q) {
$q->whereIn('name', ['S', 'RS', 'AF', 'AT']))
->when($state, fn ($q, $value) => $q->orWhere('id', $value));
})
->orderBy('name');
}
)