如何在laravelblade中显示嵌套数组数据?
How to display nested array data in laravel blade?
如何访问 laravel blade 文件中的嵌套数组数据?
我的阵列:
{
"id": 2271,
"amt_item": "PS839137",
"image_name": "PS839137.jpg",
"company": "01",
"division": "PAP",
"color_description": "VINTAGE SAGE",
"item_description": "SHT SLV CRISSCROSS TEE",
"season_code": "SP18",
"season_name": null,
"season_description": null,
"wholesale_price": ".00",
"retail_price": ".00",
"color_code": "VINSA",
"vendor_code": "DDJJG",
"vendor_desc": "JIANGYIN CITY JINGE GARMENT COMPANY",
"color_size_grid": {
"CORA": {
"1": {
"size_description": "X SMALL",
"on_hand": "0"
},
"3": {
"size_description": "MEDIUM",
"on_hand": "0"
},
"5": {
"size_description": "X LARGE",
"on_hand": "0"
},
"4": {
"size_description": "LARGE",
"on_hand": "0"
},
"2": {
"size_description": "SMALL",
"on_hand": "0"
}
},
"CHA": {
"3": {
"size_description": "MEDIUM",
"on_hand": "0"
},
"4": {
"size_description": "LARGE",
"on_hand": "0"
},
"1": {
"size_description": "X SMALL",
"on_hand": "0"
},
"5": {
"size_description": "X LARGE",
"on_hand": "0"
},
"2": {
"size_description": "SMALL",
"on_hand": "0"
}
},
"VINSA": {
"5": {
"size_description": "X LARGE",
"on_hand": "0"
},
"3": {
"size_description": "MEDIUM",
"on_hand": "0"
},
"4": {
"size_description": "LARGE",
"on_hand": "0"
},
"2": {
"size_description": "SMALL",
"on_hand": "0"
},
"1": {
"size_description": "X SMALL",
"on_hand": "0"
}
},
"VINDE": {
"5": {
"size_description": "X LARGE",
"on_hand": "0"
},
"4": {
"size_description": "LARGE",
"on_hand": "0"
},
"1": {
"size_description": "X SMALL",
"on_hand": "0"
},
"3": {
"size_description": "MEDIUM",
"on_hand": "0"
},
"2": {
"size_description": "SMALL",
"on_hand": "0"
}
}
}
}
我将此数组作为 items 传递到我的 laravel blade 文件并访问相关数据。但是我很难访问 color_size_grid 数组中的数据。如何在 foreach 循环中打印所有 size_description?提前致谢。
我的 blade 文件在做什么:
@foreach ($items as $item)
<div class="print-block" style="page-break-inside: avoid;">
<div class="print-block__img">
<img src="" alt="">
</div>
<div class="print-block__details">
<h3>{{$item['item_description']}}</h3>
<div class="code">{{$item['amt_item']}}</div>
<div class="price">
<strong>W:</strong> USD {{$item['wholesale_price']}} | <strong>R:</strong> USD {{$item['retail_price']}}
</div>
<table class="other-info">
<tr>
<td>
<strong>Sizes: </strong>
</td>
<td></td>
</tr>
<tr>
<td>
<strong>Colors: </strong>
</td>
<td></td>
</tr>
</table>
</div>
</div>
@endforeach
For Sizes,现在我想打印所有 size_descriptions inside color_size_grid数组。
每种颜色可选尺码如下:
Sizes:
CORA - X SMALL, MEDIUM, X LARGE, LARGE, SMALL
CHA - ...........
@foreach ($items as $item)
<div class="print-block" style="page-break-inside: avoid;">
<div class="print-block__img">
<img src="" alt="">
</div>
<div class="print-block__details">
<h3>{{ $item['item_description'] }}</h3>
<div class="code">{{ $item['amt_item'] }}</div>
<div class="price">
<strong>W:</strong> USD {{ $item['wholesale_price'] }} | <strong>R:</strong> USD {{ $item['retail_price'] }}
</div>
<table class="other-info">
<tr>
<td>
<strong>
Sizes:
<?php
$uniqueSizes = [];
?>
@foreach ($item['color_size_grid'] as $color => $sizes)
@foreach ($sizes as $size)
@if (isset($uniqueSizes[$size['size_description']]))
@continue
@endif
{{ $size['size_description'] }}
{{ ($loop->last ? '' : ',') }}
<?php
$uniqueSizes[$size['size_description']] = true;
?>
@endforeach
@endforeach
</strong>
</td>
<td></td>
</tr>
<tr>
<td>
<strong>
Colors:
@foreach ($item['color_size_grid'] as $color => $sizes)
{{ $color }}:
@foreach ($sizes as $size)
{{ $size['size_description'] }}
{{ ($loop->last ? '' : ',') }}
@endforeach
@endforeach
</strong>
</td>
<td></td>
</tr>
</table>
</div>
</div>
@endforeach
如何访问 laravel blade 文件中的嵌套数组数据?
我的阵列:
{
"id": 2271,
"amt_item": "PS839137",
"image_name": "PS839137.jpg",
"company": "01",
"division": "PAP",
"color_description": "VINTAGE SAGE",
"item_description": "SHT SLV CRISSCROSS TEE",
"season_code": "SP18",
"season_name": null,
"season_description": null,
"wholesale_price": ".00",
"retail_price": ".00",
"color_code": "VINSA",
"vendor_code": "DDJJG",
"vendor_desc": "JIANGYIN CITY JINGE GARMENT COMPANY",
"color_size_grid": {
"CORA": {
"1": {
"size_description": "X SMALL",
"on_hand": "0"
},
"3": {
"size_description": "MEDIUM",
"on_hand": "0"
},
"5": {
"size_description": "X LARGE",
"on_hand": "0"
},
"4": {
"size_description": "LARGE",
"on_hand": "0"
},
"2": {
"size_description": "SMALL",
"on_hand": "0"
}
},
"CHA": {
"3": {
"size_description": "MEDIUM",
"on_hand": "0"
},
"4": {
"size_description": "LARGE",
"on_hand": "0"
},
"1": {
"size_description": "X SMALL",
"on_hand": "0"
},
"5": {
"size_description": "X LARGE",
"on_hand": "0"
},
"2": {
"size_description": "SMALL",
"on_hand": "0"
}
},
"VINSA": {
"5": {
"size_description": "X LARGE",
"on_hand": "0"
},
"3": {
"size_description": "MEDIUM",
"on_hand": "0"
},
"4": {
"size_description": "LARGE",
"on_hand": "0"
},
"2": {
"size_description": "SMALL",
"on_hand": "0"
},
"1": {
"size_description": "X SMALL",
"on_hand": "0"
}
},
"VINDE": {
"5": {
"size_description": "X LARGE",
"on_hand": "0"
},
"4": {
"size_description": "LARGE",
"on_hand": "0"
},
"1": {
"size_description": "X SMALL",
"on_hand": "0"
},
"3": {
"size_description": "MEDIUM",
"on_hand": "0"
},
"2": {
"size_description": "SMALL",
"on_hand": "0"
}
}
}
}
我将此数组作为 items 传递到我的 laravel blade 文件并访问相关数据。但是我很难访问 color_size_grid 数组中的数据。如何在 foreach 循环中打印所有 size_description?提前致谢。
我的 blade 文件在做什么:
@foreach ($items as $item)
<div class="print-block" style="page-break-inside: avoid;">
<div class="print-block__img">
<img src="" alt="">
</div>
<div class="print-block__details">
<h3>{{$item['item_description']}}</h3>
<div class="code">{{$item['amt_item']}}</div>
<div class="price">
<strong>W:</strong> USD {{$item['wholesale_price']}} | <strong>R:</strong> USD {{$item['retail_price']}}
</div>
<table class="other-info">
<tr>
<td>
<strong>Sizes: </strong>
</td>
<td></td>
</tr>
<tr>
<td>
<strong>Colors: </strong>
</td>
<td></td>
</tr>
</table>
</div>
</div>
@endforeach
For Sizes,现在我想打印所有 size_descriptions inside color_size_grid数组。
每种颜色可选尺码如下:
Sizes:
CORA - X SMALL, MEDIUM, X LARGE, LARGE, SMALL
CHA - ...........
@foreach ($items as $item)
<div class="print-block" style="page-break-inside: avoid;">
<div class="print-block__img">
<img src="" alt="">
</div>
<div class="print-block__details">
<h3>{{ $item['item_description'] }}</h3>
<div class="code">{{ $item['amt_item'] }}</div>
<div class="price">
<strong>W:</strong> USD {{ $item['wholesale_price'] }} | <strong>R:</strong> USD {{ $item['retail_price'] }}
</div>
<table class="other-info">
<tr>
<td>
<strong>
Sizes:
<?php
$uniqueSizes = [];
?>
@foreach ($item['color_size_grid'] as $color => $sizes)
@foreach ($sizes as $size)
@if (isset($uniqueSizes[$size['size_description']]))
@continue
@endif
{{ $size['size_description'] }}
{{ ($loop->last ? '' : ',') }}
<?php
$uniqueSizes[$size['size_description']] = true;
?>
@endforeach
@endforeach
</strong>
</td>
<td></td>
</tr>
<tr>
<td>
<strong>
Colors:
@foreach ($item['color_size_grid'] as $color => $sizes)
{{ $color }}:
@foreach ($sizes as $size)
{{ $size['size_description'] }}
{{ ($loop->last ? '' : ',') }}
@endforeach
@endforeach
</strong>
</td>
<td></td>
</tr>
</table>
</div>
</div>
@endforeach