I am having issue sending a put request. I have tested the api using postman, when I send the request with a body of form-data and header of content-type ( application/json ), it doesn't work, infact when i dump the request, I realize nothing was sent, but again in postman if i send the request using body of raw, it works successfully, now bringing the same thing to my react native project using axios to make the same request, I get the same error as when I used form-data in postman, nothing get sent and I get error 500 (bad request). So now in the backend, I used put the request under if, so when I run the function, I get success, but nothing get sent. The thing is it sends nothing, no input at all is sent.
This is the function right here;
const setBasic = () => async ({ id }) => {
const data = new FormData();
data.append('Basic', 1)
const config = {
method: 'put',
url: `http://89bb1d61.ngrok.io/api/usersub/${id}`,
body: JSON.stringify(data),
headers: { "Content-type": "application/json" }
}
const response = await axios(config)
if (response) {
console.log(response.data)
} else {
console.log('Error')
}
}
But nothing gets sent.
This is the server side code;
public function update(Request $request, $id)
{
$user = User::find($id);
if($request->has('Basic')){
$user->Basic = $request->input('Basic');
}
// $user->Basic = $request->input('Basic');
if($request->has('Standard')){
$user->Standard = $request->input('Standard');
}
if($request->has('Premium')){
$user->Premium = $request->input('Premium');
}
$user->save();
return response()->json([
'message' => 'Success',
]);
}
It will return the success message here, (I console logged response.data) but this is because I had wrapped if around the requests. If I were to remove the if , then bad request, the input isn't received.