K1-Aria
K1-Aria

Reputation: 1146

how can i write some php code in vuejs

hi im trying to write some php code in vue js instance and components

some code like this :

<script>
window.Laravel = {};
window.Laravel.Auth = '{{ Auth::check() }}' == '' ? false : true;
window.user = '{{ Auth::user()->name }}';
window.Laravel.csrfToken = '{{ csrf_token() }}'
</script>

its working in php document in < script > tag but i need to write this into "created()" in vue js lifecycle

const app = new Vue({
   el: '#content',
      created(){
          window.user = '{{ Auth::user()->name }}';
      }
});

tnx

Upvotes: -1

Views: 3172

Answers (1)

Vinnie
Vinnie

Reputation: 31

You will only be able to use PHP in a php file not a javascript file. that is why it can be used in a tag.

also PHP renders before the page is returned from the server, so having it in the script tag will still work.

Upvotes: 3

Related Questions