BeginnerSoul's avatar

Object to array

Hello I am trying to convert object request to api controller but everytime I fail. I did try search on google and tried those methods but fails. I have these so far:

Vue

let data = new FormData();
data.append('images', this.images);

let config = {
                    headers: {
                        'Content-Type': 'multipart/form-data',
                        'X-CSRF-TOKEN': document.querySelector('meta[name="csrf-token"]').content,
                        'Authorization': `Bearer ${document.querySelector('meta[name="api_token"]').content}`
                    }
                };
       axios.post('/api/test', data, config)
                 .then(function (response) {
                    console.log(response);
                })
                .catch(function (error) {
                     console.log(error);
                 });

Controller

function api_test(Request $request)
    {

        dd($request->images);
    }

In the "this.images" format is this in the console: Name Highlight Default Description Path

However I get this: ""[object Object],[object Object],[object Object]""

How can I read those many objects? The objects volume depends on how many images the person wants to upload.

0 likes
5 replies
BeginnerSoul's avatar

Thank you for the answer. So I can't use the object in the controller but I need to loop in vue already?

Sinnbeck's avatar

What line is giving the [object Object] ? And I am confused as to why you are doing dd() in the controller?

Perhaps instead just try and return them

function api_test(Request $request)
    {

        return $request->images;
    }
BeginnerSoul's avatar

@sinnbeck because the result the same. I get more clearly the data with dd and with your method I get the same result but with white background. @haroon1296 your method is like to be "true" or "false" answer.

Well alright. I will make in javascript then to make the files to be foreach and then sending to the api. Thank you for the answers everybody. :)

Please or to participate in this conversation.