Filtering ENUMS in option list

i have this options list

->form([
Forms\Components\Radio::make('type')
->label('Type')
->default('regular')
->options(PrintOptions::class)
])

->form([
Forms\Components\Radio::make('type')
->label('Type')
->default('regular')
->options(PrintOptions::class)
])
i want to hide 2 options if the $record->parts is null this is my enum

enum PrintOptions: string implements HasLabel
{
case REGULAR = 'regular';
case AGGREGATE = 'aggregate';
case LABEL = 'label';
case RECEIPT = 'receipt';
case DATAAUTH = 'authorization';

public function getLabel(): ?string
{
return match ($this) {
self::REGULAR => 'regular',
self::AGGREGATE => 'aggregate',
self::LABEL => 'label',
self::RECEIPT => 'receipt',
self::DATAAUTH => 'Data authorization',

};
}
}

enum PrintOptions: string implements HasLabel
{
case REGULAR = 'regular';
case AGGREGATE = 'aggregate';
case LABEL = 'label';
case RECEIPT = 'receipt';
case DATAAUTH = 'authorization';

public function getLabel(): ?string
{
return match ($this) {
self::REGULAR => 'regular',
self::AGGREGATE => 'aggregate',
self::LABEL => 'label',
self::RECEIPT => 'receipt',
self::DATAAUTH => 'Data authorization',

};
}
}
i want to hide REGULAR and AGGREGATE
2 Replies
toeknee
toeknee9mo ago
array_filter ?
Soundmit
SoundmitOP9mo ago
found this
->disableOptionWhen(function (string $value, Model $record) {
return $value === 'aggregate' && $record->parts === null;
})
->disableOptionWhen(function (string $value, Model $record) {
return $value === 'aggregate' && $record->parts === null;
})
it works with one option, now i have to find the right sintax for two options but it work et voilà
->disableOptionWhen(function (string $value, Model $record) {
return $value === 'aggregate' || $value === 'regular' && $record->parts === null;
})
->disableOptionWhen(function (string $value, Model $record) {
return $value === 'aggregate' || $value === 'regular' && $record->parts === null;
})
sorry, this one

->disableOptionWhen(function (string $value, Model $record) {
return $value === 'aggregate' && $record->parts === null || $value === 'regular' && $record->parts === null;
})

->disableOptionWhen(function (string $value, Model $record) {
return $value === 'aggregate' && $record->parts === null || $value === 'regular' && $record->parts === null;
})
Want results from more Discord servers?
Add your server