Specific order for checkbox list

Repeater::make('propertyBedrooms')
->collapsed()
->label('')
->relationship()
->createItemButtonLabel('Add a new bedroom')
->columnSpanFull()
->itemLabel(fn (array $state): ?string => Str::of($state['title'])->title()->replace('_', ' ') ?? null)
->schema([
TextInput::make('title'),
RichEditor::make('description'),
CheckboxList::make('amenities')
->relationship('amenities', 'name')
->columns(4)
->options(RoomAmenity::all()->pluck('name', 'id'))

]),
Repeater::make('propertyBedrooms')
->collapsed()
->label('')
->relationship()
->createItemButtonLabel('Add a new bedroom')
->columnSpanFull()
->itemLabel(fn (array $state): ?string => Str::of($state['title'])->title()->replace('_', ' ') ?? null)
->schema([
TextInput::make('title'),
RichEditor::make('description'),
CheckboxList::make('amenities')
->relationship('amenities', 'name')
->columns(4)
->options(RoomAmenity::all()->pluck('name', 'id'))

]),
I have this repeater with checkboxlist. I am adding amenities in a specific order, but the order is not keep after save. How can I solve it? For example I am checking 1 King Bed and then Ensuite Bathroom with shower, vanity and toilet. I need the 1 King Bed to be first in the list
2 Replies
Kenneth Sese
Kenneth Sese2y ago
Do you have a sort order for your room amenities in your database? If so you should be able to do RoomAmenity::orderBy('sort_order_column')->all()->pluck('name', 'id) If you don't have a sorting column you'll need to add one to get a custom sorting since otherwise you'll be limited to the columns on your table like id, name, etc. All add it’s also the perfect opportunity to create a RoomAmenity resource and add reorderable() to it so you can just drag and drop the order you need. But again, you’ll need a sort column.
DianaMujoiu
DianaMujoiuOP2y ago
Thank you 😁
Want results from more Discord servers?
Add your server