CheckboxList Relationship Options Descriptions

How to get relationship options descriptions ? and the description should be some other column like e.g. designation: Like this: John Doe Programmer Forms\Components\CheckboxList::make('officials') ->label(false) ->relationship('officials', 'first_name', function (Builder $query, Get $get) { return $query ->orderBy('first_name') ->orderBy('last_name') ->where('board_id', $get('board_id')) ->where('member_of_board', true); }) ->getOptionLabelFromRecordUsing(fn (Model $record) => "{$record->first_name} {$record->last_name}") ->hidden(function (Get $get) { return $get('board_id') == false; }) ->columns(['sm' => 2, 'md' => 3, 'lg' => 4]) ->bulkToggleable() ->required() ->gridDirection('row')
5 Replies
Patrick Boivin
Patrick Boivin11mo ago
It looks like you need to build the list of descriptions manually for now... it could be a cool PR if you have some time to explore how to make it configurable.
Soldges
Soldges3mo ago
But manually does not work with ->relationship? Or am I doing something wrong? the descriptions are not showing
toeknee
toeknee3mo ago
Don't suppose this works?
->getOptionLabelFromRecordUsing(fn (Model $record) => new HtmlString("{$record->first_name} {$record->last_name}<small>{$record->description}</small>"))
->getOptionLabelFromRecordUsing(fn (Model $record) => new HtmlString("{$record->first_name} {$record->last_name}<small>{$record->description}</small>"))
Soldges
Soldges3mo ago
This works... But doesnt look great. But I fixed my problem... I had the wrong values in the description
toeknee
toeknee3mo ago
IT accepts HTML so you can use any classes etc. But glad you resolve it.