mardi 14 juillet 2020

Axios GET with params request shows NULL in Laravel

I am sending some data to my laravel controller using axios get request but the laravel controller shows request null.

my axios request:

const data = {
    machine_id: machine_id,
}

const api = "http://192.168.0.108:8000/api/"
const params = JSON.stringify(data)
const headers = {
    "Content-Type": "application/json",
}
axios.get(api, { params: params }, headers).then((response) => {
    consoleLog("response", response.data)
})

controller:

public function index(Request $request)
{
   dd($request->all()); // shows null

}

If I return the response instead of dd() it shows me something like below image:

public function index(Request $request)
{
   return $request->all(); // shows data

}

enter image description here

How can I catch the data in controller??



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire