If I validate my frontend form with axios by using the 'data' option it fails the validation in my backend laravel application.
axios.post('http://example.com/', {
'Content-Type': 'multipart/form-data',
Accept: 'application/json',
data: {
email: 'email@email.com',
password: '12345678',
}
}).then(res => console.log(res))
.catch(err => console.log(err));
So here I use the 'data' option to validate.
$request->validate([
'email' => 'required|string|email',
'password' => 'required|string'
]);
Returns: 422 email is required password is required.
This is how the request gets formatted:
{Content-Type: "application/json", data: {email: "email@email.com", password: "12345678"}}
However if I submit the form this way with axios it validates and I'm logged in:
'Content-Type': 'multipart/form-data',
'Accept': 'application/json',
'email': 'email@email.com',
'password': '12345678',
So my question is how to tell the validater to look inside the data object?
EDIT 1:
As requested dd($request->attributes);
returns:
ParameterBag {#53
#parameters: []
}