Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ahoi's avatar
Level 5

Post form input to API provided by another Laravel application.

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?

0 likes
1 reply
ahoi's avatar
ahoi
OP
Best Answer
Level 5

Actually it's quite easy. It has to be 'form_params' => $payload,

Please or to participate in this conversation.