Fill a Vue select from a PHP enum

Send enum cases as value and label props. Validate the posted string with Rule::enum.

For your AI agent

Copies a prompt. Paste it into the AI agent you already have open.

Read https://laravel-vuejs.space/php-enum-select-vue.md
Send enum cases as value and label props. Validate the posted string with Rule::enum.
Do not pass PostStatus::cases() straight through.
Do not validate with in:Draft,Published if the column stores draft and published.
Show the diff. Do not commit.
On this page · 3 sections
  1. The fix
  2. What to avoid
  3. FAQ

People searching “PHP enum select Vue” dump PostStatus::cases() into Inertia and then the select posts the wrong string. A backed enum has a value and a name. Store the value.

TL;DR

  • Send enum cases as value and label props.
  • Validate the posted string with Rule::enum.
  • Do not pass PostStatus::cases() straight through.
  • Do not validate with in:Draft,Published if the column stores draft and published.

Who it's for: Laravel + Vue developers

Applies to: Laravel 13 · Vue 3

The fix#

php
enum PostStatus: string
{
    case Draft = 'draft';
    case Published = 'published';
}
php
use Illuminate\Validation\Rule;

return Inertia::render('posts/Create', [
    'statuses' => array_map(
        fn (PostStatus $status) => ['value' => $status->value, 'label' => $status->name],
        PostStatus::cases(),
    ),
]);
vue
<select v-model="form.status" name="status">
  <option v-for="status in statuses" :key="status.value" :value="status.value">
    {{ status.label }}
  </option>
</select>
php
'status' => ['required', Rule::enum(PostStatus::class)],

What to avoid#

Gotcha

Do not pass PostStatus::cases() straight through. The page then has to know PHP’s enum JSON shape. Do not validate with in:Draft,Published if the column stores draft and published.

FAQ#

How do I fill a Vue select from a PHP enum?

Send enum cases as value and label props. Validate the posted string with Rule::enum.

What goes wrong with PHP enum select Vue?

Many developers dump PostStatus::cases() into Inertia and then the select posts the wrong string. Do not pass PostStatus::cases() straight through.

Found this useful?

Ask questions, share what you built.

Join thousands of Laravel and Vue developers in our Facebook group, or get new posts in your Telegram feed. Sharing this article helps too.

Keep reading

Newsletter

Get the best of Laravel & Vue, once a month.

One short email with new guides, release notes worth reading and hand-picked community links. No spam, unsubscribe any time.