Nested Object in response API

Posted 4 months ago by sktklaus

Trainer::find(1) // returns my trainer

Trainer::find(1)->fighters()->get // returns all the fighters related to this trainer

How can merge the results to get something like this?

data {
    trainer_name: "name",
    id: 1,
    fighters: [
        "id": 1,
        "nick": "hazel.hermiston",
            "battles": "46"
        "id": 2,
        "nick": "cormier.cathryn",
            "battles": "46"

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.