I'm sending Form data from a Vue component to Laravel API by POST method.
Laravel return a good response but I'm not able to manage the POST data inside the Laravel controller.
This is the client side:
let body = JSON.stringify({
'email': user.email,
'password': user.password,
});
fetch("/login", {
method: "POST",
headers: new Headers({
'Content-Type': 'application/x-www-form-urlencoded',
'X-CSRF-TOKEN': user.token, // NOTA: no X_CXRF-TOKEN
body: body
})
})
This is the controller
namespace App\Http\Controllers\Auth;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
class LoginJWTController extends Controller{
public function login(Request $request){
print_r ($request->all());
}
}
But the response (200 OK) is an empty array: array[]
On debug site I see the request header having:
body: {"email":"[email protected]","password":"12345678"}
Why I have no POST data in my Controller? What I'm missing?
Thanks for your help!
'Content-Type': 'application/x-www-form-urlencoded'to 'Content-Type': 'application/json'and one more thing why are sending your body in headers .