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
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.
But manually does not work with
->relationship
? Or am I doing something wrong? the descriptions are not showingDon't suppose this works?
This works... But doesnt look great. But I fixed my problem... I had the wrong values in the description
IT accepts HTML so you can use any classes etc. But glad you resolve it.