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

shime's avatar
Level 15

Read data Guzzle Http

I am trying to send data from one to another server using Guzzle Http... Something like this...

Server 1 (Cron Job):

    $response = $client->request('POST', $uri, [
        'form_params' => [

            'var1' => $var1,
            'var2' => $var2,
            ---
        ]
    ]);

$var1 and $var2 are associative arrays with keys 'prop1', 'prop2'... On the other side I am trying to get these values...

Server 2 (Controller):

    $request -> validate(...)
    $EloquentModel -> prop1 = $request -> var1['prop1'];
    $EloquentModel -> prop2 = $request -> var1['prop2'];
    $EloquentModel -> prop3 = $request -> var1['prop3'];
    $EloquentModel -> save()

If I remove validation part I get records inside my DB, but with empty prop1, prop2... fields. So, I don't know am I making mistake on server 1 or server 2?

0 likes
3 replies
grenadecx's avatar

Server 1 seems right.

On server 2, could you try:

$EloquentModel->prop1 = $request->get('var1.prop1');

Best would probably to write out $request->all() to a file or as a response and see what data you got to make sure it's there.

1 like
Snapey's avatar

you need to serialize the variables before sending.

Or send in another format like xml or json

1 like
shime's avatar
Level 15

@grenadecx doesn't work, but thanks for suggestion about file... I'll try that... @Snapey I don't know what does that mean, but I'll find out... :D Thanks guys... :*

Please or to participate in this conversation.