Description
Hello there,
I have a repository that queries an API for data (rather than using a model) and returns either an object or a collection. I've been trying to include this data in a transformer for another model with limited success. Obviously I cannot us includes as this requires a model relationship, so for the moment I've hackishly grabbed my interface and checking whether a property exists on the model being transformed. My only issue is that the item is not rendering... Here's my "dodgy" code:
public function transform(Domain $domain)
{
$output = [
'id' => (int) $domain->id,
'client_id' => (int) $domain->client_id,
'url' => (string) $domain->url
];
if ($id = $domain->dns_id) {
$zone = app(ZoneRepositoryInterface::class);
$output['dns'] = $this->item($zone->getById($id), new ZoneTransformer);
}
return $output;
}
$this->item($zone->getById($id), new ZoneTransformer)
appears to be the issue, it's calling the item successfully (can see object when debugging) but it's not outputting the ZoneTransformer
, just a couple of {}
.
Is there a better way of doing this? Any reason the item is not rendering?
Thanks