When fetching from an API (3rd party, I authenticate and get the data in my Laravel Controller) I get 'undefined' in the console. I want to store the data in a Vue component.
I tried a bunch of different things, including a get instead of fetch, but this also logged undefined. I did some research and read about arrow functions but I am not using an arrow function.
data() {
return {
tickets: [],
};
},
created() {
this.fetchTickets();
},
methods: {
fetchTickets() {
fetch('/api')
.then(res => {
this.tickets = res.json;
})
.then(res => {
console.log(res.json);
})
}
}
So, what I want is the collection made out of the get request I send to a 3rd party API in PHP which is returned to the route /api, stored in my Vue component. Now it just logs undefined.
EDIT Backend request in PHP
$response = $client->get('v1/tickets/search.json', [
'query' => ['statuses[]' => 'active', 'assignedTo[]' => 314955,
'sortDir' => 'desc', 'sortBy' => 'updatedAt']
]);
$json = (string)$response->getBody()->getContents();
$decoded = json_decode($json, true);
return collect($decoded);
Route: Route::get('/api', 'ApiController@getTickets',);