F
Filament3mo ago
Liam

Descriptions on CheckboxList (relationship)

Hi, I'm using this to display permissions in my user management system. Is it possible to load descriptions from the relationship without explicitly defining them in the descriptions method?
Forms\Components\CheckboxList::make('permissions')
->label('')
->relationship(
titleAttribute: 'display_name',
modifyQueryUsing: fn (Builder $query) => $query->orderBy('order'),
)
->bulkToggleable()
->columns(2),
Forms\Components\CheckboxList::make('permissions')
->label('')
->relationship(
titleAttribute: 'display_name',
modifyQueryUsing: fn (Builder $query) => $query->orderBy('order'),
)
->bulkToggleable()
->columns(2),
1 Reply
CodeWithDennis
CodeWithDennis3mo ago
Maybe you can use getOptionLabelFromRecordUsing and return a custom blade view that also contains the description? I used noticed that CheckboxList doesn't have allowHtml() so maybe you can do something like:
->getOptionLabelFromRecordUsing(function (YourModel $record) {
return new HtmlString($record->name.' <br>'.$record->description);
})
->getOptionLabelFromRecordUsing(function (YourModel $record) {
return new HtmlString($record->name.' <br>'.$record->description);
})
Not the cleanest way but hey 🤷‍♂️
Want results from more Discord servers?
Add your server