Actually I am having trouble looping a complex JSON. look at this JSON structure.
{
"transactionId": "blablablabla",
"campaigns": [
"affiliateNumbers": [
{
"phoneNumber": " 345345",
"localNumber": "(888) 34534534534-456456",
"displayNumber": "6345345345",
"assignmentSettings": {
"countryCode": "US",
"isTollFree": true,
"limit": 5
},
"deallocFlag": false,
"failedRechargeAttempts": 0,
"isCarrierNumber": false,
"carrierNumberId": "",
"isInternalOnly": false,
"affiliate": {
"accountId": "RA11a74dfgd12f3d84ee6991853ff57608715",
"id": "asddasdasd",
"subId": "",
"createNumbers": false,
"userIds": [
"475f197a-d05d-41ce-adf8-17e4fe430e46"
],
"isSelf": false,
"isCriteriaInverted": false,
"name": "Poshnee tech SMC PVT LTD",
"enabled": true,
"version": 1
},
},
]
]
}
I tried so many times I am not going to include my code cause I am really ashamed of getting laughed at. So what I want is to loop this JSON and show it in a Laravel blade.php file. How can I achieve that? IS there any easy solution for me?
Here is my Controller:
public function fetch_all_campaigns():
\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View|\Illuminate\Contracts\Foundation\Application
{
$headers = [
"Content-Type" => "application/json",
"Authorization" => "Token ****"
];
$campaigns = Http::get(
"https://api.ringba.com/v2/RA11a74d12f3d84ee6991853ff57608715/campaigns", $headers
);
return view("Dashboard.Campaigns.campaigns", [
"campaigns" => $campaigns
]);
}
CodePudding user response:
@foreach ($data["campaigns"] as $campaigns)
@foreach ($campaigns["affiliateNumbers"] as $affiliateNumbers)
<p>{{ $affiliateNumbers["affiliate"]["accountId"] }}</p>;
@endforeach
@endforeach