jeudi 6 septembre 2018

Laravel Api resource controller json format

I managed to change the format for the json response of the laravel resource controller for APIs, i want to make a key -> value response but i cant find the way to remove the brackets:

the response i get is this:

{
    "1": [
        {
            "updated_at": 1536147154
        }
    ],
    "2": [
        {
            "updated_at": 1536160598
        }
    ]
}

but i want it to be like this:

{
    "1":
        {
            "updated_at": 1536147154
        },
    "2":
        {
            "updated_at": 1536160598
        }
}

I get the response from an eloquent collection, and then I group it by id, but I don't know how to get rid of the brackets because the values end in an array.

I don't know if I am clear in my question.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire