0

I am using vue and laravel. I getting an array of objects like this in console.log(array_of_obj) :

[…]
​
0: Object { id: Getter & Setter, employee_id: Getter & Setter, manual_id: Getter & Setter, … }
​
1: Object { id: Getter & Setter, employee_id: Getter & Setter, manual_id: Getter & Setter, … }
​
2: Object { id: Getter & Setter, employee_id: Getter & Setter, manual_id: Getter & Setter, … }

Each object contains my desired row data. Now I want to send it to Laravel controller via axios post request. How Can I do this? I have tried this way:

let json=JSON.stringify(array_of_obj);
let post_data={json_data:json}
 store.dispatch('employees/EmployeeListDownloadPdf', post_data).catch(err => { console.error(err) })

In my vuex section:

EmployeeListDownloadPdf(ctx, employeeList) {
                return new Promise((resolve, reject) => {
                    
                    axios({
                        url: '/api/employees/employeeListData',employeeList,
                        method: 'POST',
                        
                      })
                        //.then(response => resolve(response))
                        .then((response) => {
                            //console.log(response.data)
                            
                          });
                        //.catch(error => reject(error))
                })
            },  

But in my controller I tried with following code but getting empty array.

dd(json_decode($request->all(),true));
dd(json_decode($request,true));

I want to get all data into my controller but can not accesss them now. How Can I do this?

2
  • I think you need to show us what the VueX action employees/EmployeeListDownloadPdf does. What you've shared doesn't show how your VueJS app sends the data to the server. Commented Feb 19, 2021 at 19:22
  • updated now. Please check Commented Feb 19, 2021 at 19:26

1 Answer 1

1

You're using axios() incorrectly: if you read the docs, the employeeList needs to be assigned to the data property in the object, i.e.:

axios({
    url: '/api/employees/employeeListData',
    data: employeeList,
    method: 'POST'
})
Sign up to request clarification or add additional context in comments.

1 Comment

Now i Can get my data in Controller. Thanks a lot.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.