@foreach($variationTypeCollection as $key => $var)
do some thing
@foreach($collection as $col)
{{ $col->variationId.$key++ }}
@endforeach
@endforeach
如何使用密钥连接属性
我希望它看起来像变异Id1,变异Id2
谢谢。
试试这个
@foreach($collection as $col)
{{ $col->{'variationId' . $key++ } }}
@endforeach
为了更好的可读性
@foreach($collection as $col)
@php($property = 'variationId' . $key++)
{{ $col->{$property} }}
@endforeach
@foreach($collection as $col)
{{ $col->variationId }}{{ $loop->iteration }}
@endforeach
这可能会解决您的问题