kenshin9's avatar

Laravel Mix Environment Variables and Booleans

Hey everyone. Is there a way to use boolean environment variables with Laravel Mix? For example, I'm trying to set up Echo so that we can configure the security related flags based on the environments.

window.Echo = new Echo({
    encrypted: process.env.MIX_ECHO_ENCRYPTED,
    forceTLS: process.env.MIX_ECHO_FORCE_TLS,
    disableStats: true,
});

I've shortened the example for brevity. But once compiled, it ends up looking like:

window.Echo = new Echo({
    encrypted: "true",
    forceTLS: "false",
    disableStats: true,
});

Any input would be appreciated. Thanks in advance!

0 likes
4 replies
Sinnbeck's avatar

What if you use 0 and 1? They are still boolean flags

kenshin9's avatar

Sorry, I hadn't seen the reply. I had tried that, but both "0" and "1" are still truthy.

Sinnbeck's avatar

@kenshin9 no worries. It does not seem to be possible. But you can do

encrypted: process.env.MIX_ECHO_ENCRYPTED === 'true',

Please or to participate in this conversation.