0

I have created a function in my controller that receives a request and does some calculations after that and stuff. Currently I am just showing the request array for checking:

public function check_availability(Request $request){
        dd($request->all());
        //other works to use this request values
         
    }

Now when I am sending a request to the route which hits this function using postman like this: enter image description here

So it is working perfectly from postman. But the same request is returning blank request array when I am sending the request from my vue js application.

var data= {
          "qty": 1000,
          "id": 1
        }
        var config = {
          method: 'get',
          url: 'http://127.0.0.1:8000/api/check_quantity',
          data: data
        };

        axios(config)
        .then(function (response) {
          console.log("returned :", response)
          commit('set_products', payload);
        })
        .catch(function (error) {
          console.log("this is error:",error);
        });

This is returning blank array! This is working when I am configuring the whole system in POST method. How can I solve this using get method?

1 Answer 1

1

to pass data in get method you have to add them in query params like ?=foo=bar

so your code should like like

var data= {
  qty: 1000,
  id: 1
}
var config = {
  method: 'get',
  url:`http://127.0.0.1:8000/api/check_quantity?qty=${data.qty}&id=${data.id}`,
};

axios(config)
.then(function (response) {
  console.log("returned :", response)
  commit('set_products', payload);
})
.catch(function (error) {
  console.log("this is error:",error);
});

Sign up to request clarification or add additional context in comments.

2 Comments

So there is no way of sending body data with get method? I knew this parameter way, but wanted to use the body data way.
body and params is different post request have body and get request have params to send data. it is http protocol's term. and postman also behind the seen doing this

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.