mercredi 9 mars 2016

Displaying nested json in laravel 5.2

I have a nested json file

{
        "event_type": "INCOMING_BTC",
        "event_uid": "5515c5601f7b3",
        "datetime": "2015-03-27 21:02:37",
        "resources": [
            {
                "resource_type": "transaction",
                "resource": {
                    "id": 105062,
                    "datetime": "2015-03-27 21:02:23",
                    "description": "Money from Xapo Tip",
                    "order_type": "payment_received",
                    "from": {
                        "type": "btc_address",
                        "id": "1AqF787aPHgPRZ81kdQSeEwW46yjyrAaxR"
                    },
                    "to": {
                        "destination_type": "btc_address",
                        "destination_id": "1N65Bz88zKUDPKhUUsx8f9Qwsuo96Hqz7S",
                        "to_account": 1276
                    },
                    "generic_type": "credit",
                    "amount": "0.0000001",
                    "currency": "BTC",
                    "status": "completed",
                    "txConfidence": 1,
                    "rejection_reason": null,
                    "notes": null,
                    "base_currency": "USD",
                    "exchange_rate": null,
                    "exchange_amount": null
                }
            },
            {
                "resource_type": "address",
                "resource": {
                    "id": "1N65Bz88zKUDPKhUUsx8f9Qwsuo96Hqz7S",
                    "address": "1N65Bz88zKUDPKhUUsx8f9Qwsuo96Hqz7S",
                    "meta_data": null,
                    "label": null,
                    "total_received": "0.00000350",
                    "created_at": "2015-03-08 14:50:59",
                    "address_type": "multisig",
                    "id_account": "1276"
                }
            }
        ]
    }

And I have saved this file in public folder with name xapojson.txt

In my routes file I have done json_decode to decode this data to a variable 'transaction' and passed it to view

 Route::get('/', function () {
    $transaction = json_decode(file_get_contents('xapojson.txt'));
    return view('transaction', compact('transaction'));
});

Now in transaction view I have to display the data from this nested json. I have tried out lots of variation and searched on google and stackoverflow but nothing worked. I found this somewhat helpful Check this out. But it also do not get into more nesting.

In the view I have to display these datas:-

resources[0]->resource->from->type

resources[0]->resource->id

resources[0]->resource->from->id

resources[0]->resource->status

resources[0]->resource->amount

resources[0]->resource->currency

resources[0]->resource->to->destination_id

datetime

Please help me on displaying the above fields.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire