vendredi 22 janvier 2016

Nested Transformation with Fractal, Dingo API, Laravel 5

I'm trying to transform a collection of tickets with the following code

public function transform(Ticket $ticket) {
    return [
        'id' => $ticket->id,
        'title' => $ticket->title,
        'status' => $this->transformerMessage($ticket->status),
        'interactions' => 
              $this->collection(
                   $ticket->interactions,
                   new InteractionTransformer(),
                   'interactions'
              )
    ];
}

But the interactions result is always empty. Here is an example of output I'm getting:

{
  "data": [
    {
      "id": 1,
      "title": "Earum repudiandae corporis sapiente at odit itaque ratione.",
      "status": "Open",
      "interactions": {}
    },
    {
      "id": 2,
      "title": "Odit impedit vitae quo sit molestiae eius.",
      "status": "Open",
      "interactions": {}
    },
    {
      "id": 3,
      "title": "Fuga cum corrupti ut.",
      "status": "Open",
      "interactions": {}
    }
  ]
}

if I try to die and dump the $ticket->interactions variable, I get a Collection of 5 items (which proves the variable isn't empty).

What am I doing wrong here?

Thanks for your attention.



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1OMuyME
via IFTTT

Aucun commentaire:

Enregistrer un commentaire