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

SYPOMark's avatar

Declaring app.name in vue.js files

Hi there,

I hope that somebody can help with what is probably (hopefully) quite a straightforward thing.

I've found this post https://laracasts.com/discuss/channels/laravel/what-is-the-standard-way-to-declare-the-application-name on how to declare the app.name in blades, but I am wondering how I should make use of app.name in a vue.js file?

I've tried inserting:

app.name

and;

{{ config('app.name')}}

and;

config('app.name')

all to no avail.

It feels like I am almost there, just missing something.

if it's any help, this be the context of the usage:

initializeForm() {
    this.form.message = 'Hello ' + this.user.name + ', from ' + app.name + '.';
    // Need to replace app.name with something that works
},

Any help with this would be most appreciated. I mean, I could just try adding the name manually, but the name we've chosen, isn't set, so, I am anticipating having to use the same thing elsewhere. It'd be good if I didn't have to later on go through manually editing lots of files.

With kind regards,

Mark

0 likes
2 replies
Cronix's avatar
Cronix
Best Answer
Level 67

The place to add global variables is into the main template where they create the Spark global object. They have an empty array there just after Spark::scriptVariables() for you to put your own variables.

/resources/views/vendor/spark/layouts/app.blade.php

<!-- Global Spark Object -->
<script>
     window.Spark = <?php echo json_encode(array_merge(
         Spark::scriptVariables(), [
             'app_name' => config('app.name')
         ]
     )); ?>;
</script>

Then in js, just access with "Spark.app_name" or whatever key you assign it.

1 like
SYPOMark's avatar

@Cronix

Thanks very much for your swift answering of this question. It'd got me foxed. I've implemented your suggestion and it works perfectly.

Thanks again,

Mark

1 like

Please or to participate in this conversation.