Search code examples
nestedincluderelationshipthephpleague-fractal

League Fractal including multiple nested relationships


How can I include multiple child relationships using ?include=?

Example: /store/1?include=books.author:downloads

The result would produce:

[
    id: 1,
    name: 'Book Name',
    author: {
        data: {
            id: 1,
            name: 'Author name'
        }
    },
    downloads: {
        data: {
            weekly: 100,
            monthly: 1000
        }
    }
]

I left out most of the object, just the core of what I'm requesting.


Solution

  • As it turns out you simply include books twice and it knows to merge them together.

    So: /store/1?include=books.author,books.downloads

    It would be nice to have that documented somewhere. If it is and I've missed it please let me know.