Laravel is not defined Laravel is not defined vue.js vue.js

Laravel is not defined


Or for a cleaner format:

<script>    window.Laravel = { csrfToken: '{{ csrf_token() }}' };</script>

Does same thing as Rocco's answer.


Try to put this on your blade, as you can see is inserted by default on app.blade on Laravel 5.3

<script>    window.Laravel = <?php echo json_encode([        'csrfToken' => csrf_token(),    ]); ?></script>


if you're using axios then ensure the following is in your bootstrap.js file after axios is imported:

window.axios.defaults.headers.common = {    'X-CSRF-TOKEN': document.querySelector('meta[name="csrf-token"]').getAttribute('content'),    'X-Requested-With': 'XMLHttpRequest'};