lundi 7 août 2017

JSON response in Laravel

I am accessing an API and I get a JSON response from this API:

{
    "products": [
        {
            "id": 455968,
            "name": "Nike Satire",
            "shortName": "Nike Satire",
            "priceMin": 199.99,
            "priceMax": 199.99,
            "discount": 0,
            "thumbnail": {
                "url": "http://ift.tt/2uiY9OL",
                "height": 600,
                "width": 600,
                "otherFormats": [
                    {
                        "url": "http://ift.tt/2uz9DZU",
                        "height": 100,
                        "width": 100
                    },
                    {
                        "url": "http://ift.tt/2ui9kYe",
                        "height": 200,
                        "width": 200
                    },
                    {
                        "url": "http://ift.tt/2uz0UH0",
                        "height": 300,
                        "width": 300
                    },
                    {
                        "url": "http://ift.tt/2uiY9OL",
                        "height": 600,
                        "width": 600
                    }
                ]
            },
            "hasOffer": 2
        },
        {
            "id": 611192,
            "name": "Nike Air Vapor Ace",
            "shortName": "Nike Air Vapor Ace",
            "priceMin": 229.99,
            "priceMax": 229.99,
            "discount": 0,
            "thumbnail": {
                "url": "http://ift.tt/2uimaWk",
                "height": 600,
                "width": 600,
                "otherFormats": [
                    {
                        "url": "http://ift.tt/2uz7L37",
                        "height": 100,
                        "width": 100
                    },
                    {
                        "url": "http://ift.tt/2uiJmno",
                        "height": 200,
                        "width": 200
                    },
                    {
                        "url": "http://ift.tt/2uzqJqx",
                        "height": 300,
                        "width": 300
                    },
                    {
                        "url": "http://ift.tt/2uimaWk",
                        "height": 600,
                        "width": 600
                    }
                ]
            },
            "hasOffer": 1
        }
    ]
}

And in the view I am trying to display this information as:

    <div class="container container-margin">
        <div class="list-group">
            @foreach($produtos->products as $t)
            <a href="" class="list-group-item"><img src=""> - from  to </a>
            @endforeach
        </div>
    </div>

My problem is: How can I display the thumbnail url?

I tried the following approaches:

@foreach($t->thumbnail as $v) @endforeach

Nothing seems to work when trying to get a child of a child.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire