Level 5
Actually it's quite easy. It has to be 'form_params' => $payload,
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hello there :-)
I would like to make a POST-request containing form data to a Laravel-based app, which provides an API.
Actually the remote Laravel-API accepts checks this:
/*Validate request*/
$request->validate([
'data.email' => 'required|string|email|max:255|unique:users,email',
]);
If I now do a POST-request like this:
$payload = [ 'data' => [
'email' => $request->input('data.email'),
]
];
$response = $client->request('POST',
'https://'.config('server').$route, [
'headers' => [
'Accept' => 'application/json',
'Authorization' => 'Bearer '.$this->getAccessToken(),
],
$payload,
]);
The validation fails:
"message":"The given data was invalid.","errors":{"email":"The email field is required."
So my question: How can I create a POSTable array that can be validated by the API?
Actually it's quite easy. It has to be 'form_params' => $payload,
Please or to participate in this conversation.