Skip to content

Embeds are nested one level too much #39

@Anahkiasen

Description

@Anahkiasen

When using embeds, straight from the Fractal docs :

class ResortTransformer extends \League\Fractal\TransformerAbstract
{
    /**
     * Embed if requested
     *
     * @var array
     */
    protected $availableEmbeds = ['amenities'];

    /**
     * Embed amenities on the resort
     *
     * @return Collection
     */
    public function embedAmenities(Resort $resort)
    {
        return $this->collection($resort->amenities, new AmenityTransformer);
    }
}

Instead of getting this:

{
    "name": "something",
    "amenities": [
        {
            "an": "amenity"
        },
        {
            "another": "amenity"
        },
    ]
}

I'm getting this:

{
    "name": "something",
    "amenities": {
        "data": [
            {
                "an": "amenity"
            },
            {
                "another": "amenity"
            },
        ]
    }
}

Is this expected behavior ? And if yes is there a workaround? Or is it a Fractal issue?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions