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

lirone's avatar

Prevent formatting only JS on blade file (VScode)

Hi,

I have a blade file with some js code. I have this following setting on VS Code to format on save which is pretty convenient:

  "[blade]": {
    "editor.formatOnSave": true,
    "editor.insertSpaces": false,
    "editor.defaultFormatter": "amirmarmul.laravel-blade-vscode"
  },

However, on my script, I have this line

<script>
    let stripe = Stripe("{{ env("STRIPE_KEY")}}");
</script>

which is transformed to after formatting

 let stripe = Stripe("{{ env("
        STRIPE_KEY ")}}");

which of course does not work anymore since it's not inline.

Is there a solution to format on a same file both JS and HTML/Blade without impacting the syntax ?

Thank you in advance

0 likes
7 replies
Sinnbeck's avatar

Never use env() outside of config files! It wont work in production

Sinnbeck's avatar

@lirone You can add it to a config file and reference that. LEts say you add it to auth.php with the key stripe_key

config('auth.stripe_key')
1 like
lirone's avatar

@Sinnbeck So the best practice is to call config('cashier.key') on the controller and pass it to js ? or like that:

var cfg = "{{ config('cashier.key') }}"

directly ?

Sinnbeck's avatar

@lirone Thats what I would do, but using the config helper in blade isn't terrible :)

Please or to participate in this conversation.