-1

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

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.