I am trying to send Form data from a Vue component to a Laravel API using the POST method.
Although Laravel is returning a successful response, I am encountering difficulty in handling the POST data within the Laravel controller.
Below is the code for 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,
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());
}
}
However, the response (200 OK) returns an empty array: array[]
Upon inspecting the request header, I notice the following:
body: {"email":"example@email.com","password":"12345678"}
Why am I not receiving any POST data in my Controller? What could be missing?
Thank you for your assistance!