CristalTeam / php-api-wrapper

:rainbow: Work with APIs like with Laravel Eloquent or Doctrine (no longer a dream)
MIT License
119 stars 32 forks source link

Empty result #56

Closed lpcs007 closed 4 months ago

lpcs007 commented 4 months ago

I need help using the package. Here's a summary of what I did and the problem I'm facing:

I'm trying to retrieve records from an API endpoint using the following code:

$curl = new \Curl\Curl();
$curl->setHeader('X-Token', 'my_token');
$transport = new \Cristal\ApiWrapper\Transports\Transport('https://myurl/get_records', $curl);

$api = new \Cristal\ApiWrapper\Api($transport);
\App\Models\MyModel::setApi($api);

dd(\App\Models\Record::get());

When I make the request using Guzzle, the expected JSON response looks like this:

{
  "status": true,
  "response": [
    {
      // records here
    }
  ]
}

However, when using the CristalTeam/php-api-wrapper package, the response I'm getting is:

#items: array:3 [▼
  "response" => App\Models\Record {#2674 ▶}
  "response_code" => App\Models\Record {#2672 ▶}
  "status" => App\Models\Record {#2671 ▶}
]
#escapeWhenCastingToString: false

Additionally, the "response" field is empty. Could anyone please assist me in identifying what might be causing this discrepancy?

Thanks in advance for the help.

lpcs007 commented 4 months ago

I found the solution. I didn't know that $entity was passed as an endpoint. I also extended Transport and included the 'response' array in the result.