Reputation: 1146
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
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