I have a laravel and vue js application, I'm having intermittent issues with a get request with Vue JS & Axios, I can hit the route directly in my browser and it works fine the data is returned. I load my view which calls the data via Axios with Vue JS and sometimes it works and sometimes it doesn't.. I find that if I open the debugger on the right of my chrome the call fires and it works fine. Close and it fails.
Error being returned:
Failed to load resource: the server responded with a status of 500 (Internal Server Error) Uncaught (in promise) Error: Request failed with status code 500
My laravel route is as follows:
Route::get('/orders/today','OrdersController@today');
My vuejs file has the following:
axios.defaults.headers.common['X-CSRF-TOKEN'] = document.querySelector('#_token').getAttribute('value');
var vue = new Vue({
el: '#app',
data: {
orders: [],
estimates: []
},
mounted : function()
{
this.getOrders();
},
methods: {
getOrders: function() {
axios.get('/orders/today').then(response => [this.orders = response.data.data, this.estimates = response.data.data2]);
console.log(this.orders);
}
}
})