Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

jnkconsult's avatar

Vue 3 and php 8 Enum

Hello,

I have create a enum type in my projet :

enum LocationReportTypeEnums: string
{
    case EMAIL = 'email';
    case API = 'api';
    case SFTP = 'sftp';
}

Now, I have a table with the datas (customers) and I try to use this enum in a class binding (customer.delivery come from the object in my v-for and I will check this data with the enum) :

<div class="border-1 rounded-lg text-center uppercase" :class="customer.delivery_type == App\Enums\LocationReportTypeEnums::EMAIL  ? 'bg-green-600 text-gray-800' : 'bg-blue-600 text-yellow-200'">
                                                    {{ customer.delivery_type }}
 </div>

But this is not working...How can i used my enum in a vue 3 class binding ?

Thanks you

0 likes
1 reply
rodrigo.pedra's avatar

Your PHP objects won't be available in JavaScript. You need to compare to the value.

<div class="border-1 rounded-lg text-center uppercase" :class="customer.delivery_type == 'email'  ? 'bg-green-600 text-gray-800' : 'bg-blue-600 text-yellow-200'">
    {{ customer.delivery_type }}
 </div>

Please or to participate in this conversation.