Implement Selectable for models and classes
mainTo avoid manually defining label and value fields every time you use a model in Options, implement the Selectable interface on your class. This allows you to define a toSelectOption() method that returns a SelectOption object.
This method can also include extra data that will be appended to the resulting options array.
class Wizard extends Model implements Selectable
{
public function toSelectOption(): SelectOption
{
return new SelectOption(
$this->getName(),
$this->getUuid(),
['color' => $this->color]
);
}
}
// Usage becomes simple:
Options::forModels(Wizard::class);