When developing web applications, you probably encounter a lot of places where someone needs to select one or more options in a select or multi-select. These select boxes always need a list of options with labels and values. In one of our projects, we had options being generated in lots of places.

For example, let's say you have an enum like this: enum Hobbit: string { case Frodo = 'frodo'; case Sam = 'sam'; case Merry = 'merry'; case Pippin = 'pippin'; } You can easily convert this to a list of options like this: Options::forEnum(Hobbit::class)->toArray(); Which will return the following array: [['label' => 'Frodo', 'value' => 'frodo'], ['label' => 'Sam', 'value' => 'sam'], ['label' => 'Merry', 'value' => 'merry'], ['label' => 'Pippin', 'value' => 'pippin'], ]
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future. Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future.
Community Partners