Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

cedricmatalog's avatar

({response})

when trying to remove the curly brace it does not work.

axios.get('/api/tours')
    .then(({response}) => {
        this.tours = response.data;
}
);
    

why do we need to wrap the "response" in a curly brace?

0 likes
4 replies
michapietsch's avatar

Seems the response is not an object and by adding the curly braces you create an object from an array.

Please check the response in DevTools to see what you get from the server.

1 like
cedricmatalog's avatar

@MICHAPIETSCH - That makes sense.

public function index()
{
    $tours = Tour::all();
        return TourResource::collection($tours);
 }

This works.

axios.get('/api/tours')
.then(({data}) => {
 this.tours = data.data;
 });

This does not work.

axios.get('/api/tours')
    .then(({response}) => {
        this.tours = response.data;
}
);

I'm assuming this should be "data" because it is the standard return for collections?

1 like
D9705996's avatar
D9705996
Best Answer
Level 51

The {} are destructing the object and giving you back the objects data property as s data variable.

If you do

.then((response) => {
 console.log(response);
});

You should see an object with a data key in dev tools. You can see the response schema in the axios docs where you can see you get a data property.

https://github.com/axios/axios#response-schema

1 like

Please or to participate in this conversation.