ErrorException Array to string conversion - Error sending an array to a url

0

I'm trying to send some data to an API service that I am consuming the service route type resource and I send data to that route. I get the following error:

(1/1) ErrorException
Array to string conversion

in beneficiosController.php (line 69)
at HandleExceptions->handleError(8, 'Array to string conversion', '/Users/user/Desktop/users/app/Http/Controllers/transactionController.php', 69, array('request' => object(Request), 'client' => object(Client), 'data' => array('code' => '2270', 'item_code' => '82', 'user' => '555', 'pack_id' => '52', 'transaction_status' => '1', 'transaction_id' => null)))

I'm using this control

public function transaction(Request $request){

        $client = new Client();

        $data = [
            "code" =>  $request['code'],
            "item_code" => $request['item_code'],
            "user" => $request['user'],
            "pack_id" => $request['pack_id'],
            "transaction_status" => $request['transaction_status'],
            "transaction_id" => $request['transactransaction_idtion_status'],
            ];

        $response = $client->get("http://localhost:8000/v1/transaction". $data  );

        echo $response->getBody();

    }

How should I send the url with the $ data?

    
asked by Cesar Augusto 02.08.2017 в 19:31
source

2 answers

0

If you are using GuzzleHttp\Client , the solution is to pass a array as a second parameter and within this indicate form_params equal to $data .

So for example:

$response = $client->get("http://localhost:8000/v1/transaction", [
  'form_params'=> $data
]);
    
answered by 02.08.2017 / 20:37
source
0

If you need to pass an Array by GET you can do it with link

Example:

<?php
$data = array('foo'=>'bar',
          'baz'=>'boom',
          'cow'=>'milk',
          'php'=>'hypertext processor');

$data =  http_build_query($data);

$url= "http://localhost:8000/v1/transaction?". $data;

Documentation:

link

    
answered by 02.08.2017 в 19:43